#P7241. [COCI 2019/2020 #4] Holding
[COCI 2019/2020 #4] Holding
Background
Ivica has a group consisting of Croatian companies, but his group is facing difficulties. His businesses have huge debts, so the government sent lawyers to confiscate all his property.
However, we found that although he is deeply in debt, he still reached an agreement with the government and managed to keep some of the companies. Which ones did he keep? We now know.
Problem Description
The lawyers put debt documents of Ivica’s companies on the table. The debt of the first company is , the debt of the second company is , and so on.
Ivica reached an agreement with the government so that he can keep all companies corresponding to the documents in the interval on the table, but he must take on all debts , where and 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 and position for a price of .
Ivica is a bit desperate. He only has 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 .
The second line contains integers, where the -th one is .
Output Format
Output one integer in one line, the minimum total debt after spending at most 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 |
|---|---|---|
| , | ||
| , | ||
| No special constraints |
For of the testdata, it is guaranteed that , , , .
【Hints and Help】
This problem is translated from COCI 2019/2020 CONTEST #4 T3 Holding.
In COCI, this problem is worth points.
Translated by ChatGPT 5