#P7241. [COCI 2019/2020 #4] Holding

[COCI 2019/2020 #4] Holding

Description

The lawyers put NN debt documents of Ivica’s companies on the table. The debt of the first company is A1A_1, the debt of the second company is A2A_2, and so on.

Ivica reached an agreement with the government so that he can keep all companies corresponding to the documents in the interval [L,R][L, R] on the table, but he must take on all debts AL,AL+1ARA_L, A_{L+1}\ldots A_R, where LL and RR are positions among the row of documents on the table.

Fortunately, the lawyers are also corrupt. They can let him swap the documents currently placed at position ii and position jj for a price of ij|i-j|.

Ivica is a bit desperate. He only has KK dollars in his pocket, and he now wants to spend this money here so that the debt he needs to take on is as small as possible.

Please help him achieve this goal.

Input Format

The first line contains four integers N,L,R,KN, L, R, K.

The second line contains NN integers, where the ii-th one is AiA_i.

Output Format

Output one integer in one line, the minimum total debt after spending at most KK dollars.

3 2 2 1
1 2 3
1
5 2 3 3
21 54 12 2 0
12
6 4 6 100
1 2 3 4 5 6
6

Hint

【Constraints】

Subtask ID Special Constraints Score
11 N13N \le 13, R=NR = N 2020
22 N50N \le 50, R=NR = N 3030
33 N50N \le 50
44 No special constraints 2020

For 100%100\% of the testdata, it is guaranteed that 1N1001 \le N \le 100, 1LRN1 \le L \le R \le N, 1K1041 \le K \le 10^4, 1Ai1061 \le A_i \le 10^6.

【Hints and Help】

This problem is translated from COCI 2019/2020 CONTEST #4 T3 Holding.

In COCI, this problem is worth 110110 points.

Translated by ChatGPT 5