|| ||Code Submission Evaluation System
CSES Problem Set
Task | Statistics
CSES - Increasing ArrayCSES - Increasing Array
|Time limit:||1.00 s
||Memory limit:||512 MB|
You are given an array of $n$ integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element.
On each turn, you may increase the value of any element by one. What is the minimum number of turns?
The first input line contains an integer $n$: the size of the array.
Then, the second line contains $n$ integers $x_1,x_2,\ldots,x_n$: the contents of the array.
Print the minimum number of turns.
- $1 \le n \le 2 \cdot 10^5$
- $1 \le x_i \le 10^9$
3 2 5 1 7