Buddy on the increasing spree

0

0 votes
Medium
Problem

As buddy was done with his love for consecutive numbers, now he is onto the increasing numbers. He finds N boxes ith of which has A[i] balls. He wants these boxes to be in such a way that starting from index 1 all of them have number of balls in strictly increasing order. It takes him unit time to take or add any amount of ball to any box. You need to tell the minimum amount of time so that he can get his favourite arrangement.

Constraints:
1 ≤ N ≤ 103
1 ≤ A[i] ≤ 107

Input:
First line of input contains the number N, number of elements in the array. Second line contains N space seperated integers.

Output:

Output a single integer showing the required minimum time to get the desired arrangement.

Sample Input
4
2 4 3 8
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the given array you can change 3 to any value between 4 and 8 by adding the required ball in unit time to satisfy the given condition.

Editor Image

?