eolymp
bolt
Try our new interface for solving problems
Problems

Minimum increments

Minimum increments

Given array with $n$ positive integers. Find the minimum number of operations required so that an Arithmetic Progression with the array elements is achieved with common difference as $1$. In a single operation, any element can be incremented by $1$. \InputFile First line contains number $n~(n \le 10^6)$. Second line contains $n$ positive integers, each is no more than $10^6$. \OutputFile Print the minimum number of operations to get an Arithmetic Progression with common difference as $1$. \Example In the first test array must be converted to $8~9~10~11~12$. In this case we'll make $(8 - 3) + (9 - 6) + (10 - 4) + (11 - 11) + (12 - 5) = 5 + 3 + 6 + 0 + 7 = 21$ operations.
Time limit 3 seconds
Memory limit 128 MiB
Input example #1
5
3 6 4 11 5
Output example #1
21
Input example #2
5
4 4 5 5 7
Output example #2
5