You have an array of length
that are initially zero. In each step, you may choose a consecutive interval
and increase the values by 1. Find the minimum number of operations required so that the
-th entry of the array is equal to
.
Input Specification
The input file has two lines. The first line has an integer
denoting the length of the array. The second line contains
integers separated by one space. The
-th integer denotes
.
Output Specification
The output contains only one integer denoting the minimum number of operations required.
Sample Input
Copy
6
4 3 2 5 3 5
Sample Output
Copy
9
Explanation
One possible optimal solution is to choose
as the subintervals to increment.
Constraints
For
of test data,
.
For
of test data,
.
For
of test data,
,
.
Comments
Since the original data were weak, an additional test case was added, and all submissions were rejudged.
An additional test case was added again, and all submissions were rejudged.