#P6507. [CRCI2007-2008] NIKOLA
[CRCI2007-2008] NIKOLA
Problem Description
There is a row of cells, numbered . Nikola starts from cell and wants to reach cell .
His trip consists of several jumps. The first jump can only go to cell . After that, every jump must satisfy the following rules:
-
If he jumps in the direction of cell , then each time he must jump a distance that is exactly cell longer than the previous jump.
-
If he jumps in the direction of cell , then each time he must jump a distance exactly the same as the previous jump.
For example, after the first jump (standing on cell ), Nikola can choose to jump to or to .
Each time he enters a cell, Nikola must pay the corresponding entry fee. The fee for cell is . He wants to spend as little money as possible while still being able to reach cell . You need to compute this minimum value.
Input Format
The first line contains an integer , the number of cells.
The next lines each contain an integer , in order, representing the entry fee for cells .
Output Format
Output one integer in a single line, the minimum total cost.
Note: the starting cell is free at the beginning, but if a cell is visited multiple times, you must pay each time you enter it.
6
1
2
3
4
5
6
12
8
2
3
4
3
1
6
1
4
14
Hint
Sample 1 Explanation
In the first sample, Nikola’s route is . The total cost is .
Constraints
For of the testdata, it is guaranteed that , .
Notes
Translated from COCI2007-2008 Regional Competition T2 NIKOLA。
Translated by ChatGPT 5