Problem list
Log in
#coci00543 · COCI 2019/2020 Contest 4

Holding

Platinum II 2.0 s 256 MB

Difficult times lie ahead of Ivica and his Holding – a group of $N$ Croatian companies that are in his ownership. Each of these companies is in debt so the state sent its attorneys to take everything away from him. We have exclusively found out that Ivica managed to make a deal with the state to leave him certain companies in spite of the massive debt. Which ones? We found that out as well. The state attorneys have laid out $N$ proprietary papers of Ivica’s companies on the table. The debt of first company is written on the first paper $A_{1}$, the debt of the second company is written on $A_{2}$, . . . and the debt of the last company is written on the last paper $A_{N}$. Ivica made a deal with the state to leave the companies $A_{L}$, $A_{$L+1$}$, . . . , $A_{R}$ in his ownership, where $L$ and $R$ represent the positions in an array of papers on the table. Fortunately for Ivica, the attorneys are (also) corrupt. They will force him to take the same contiguous subarray as agreed upon (from $L$-th to $R$-th paper), but they will let him swap any two papers on the table for a specific cost. More precisely, swapping papers at positions $i$ and $j$ will cost him |$i - j$| kunas (Croatian currency). Ivica is desperate. He has only $K$ kunas in his pocket which he now wishes to spend in such a way that the sum of debts of companies he is left with is as small as possible. Help Ivica achieve his goal.

Input

The first line contains four space-separated integers $N$, $L$, $R$ ($1 \le L \le R \le N \le 100$) and $K$ ($0 \le K$ ≤ 10 000) from the task description. The second line contains $N$ integers $A_{i}$ ($0 \le A_{i} \le 10^{6}$) from the task description.

Output

You should output a single integer which represents the smallest amount of total debt Ivica will have if he spends his $K$ kunas optimally.

Constraints

Subtask 1 (22 points): $N \le 13$ and $R = N$

Subtask 2 (33 points): $N \le 50$ and $R = N$

Subtask 3 (33 points): $N \le 50$

Subtask 4 (22 points): No additional constraints.

Example 1

Input
3 2 2 1
1 2 3
Output
1

Example 2

Input
5 2 3 3
21 54 12 2 0
Output
12

Example 3

Input
6 4 6 100
1 2 3 4 5 6
Output
6
Source
COCI 2019/2020 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code