Problem 975
Minimum Operations to Make the Array Increasing
Problem
In one operation you increase any element by 1. Find the minimum number of operations that makes the array strictly increasing (each element larger than the one before it). Scan from left to right: if an element is not larger than the previous one (after its own increases), raise it to previous + 1 and add the difference to the count. Raising each element as little as possible is clearly optimal.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].
Output
Print the minimum number of operations.
Constraints
1 <= N <= 5000; 1 <= A[i] <= 10^4
Example input
3 1 1 1
Example output
3
Explanation
For 1 1 1, raise the second element to 2 (1 operation) and the third to 3 (2 operations), giving 1 2 3 after 3 operations.