7479: [CSES Problem Set] Increasing Array
[Creator : ]
Description
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 move, you may increase the value of any element by one. What is the minimum number of moves required?
On each move, you may increase the value of any element by one. What is the minimum number of moves required?
Input
The first input line contains an integer $n$: the size of the array.
Then, the second line contains $n$ integers $x_1,x_2,…,x_n$: the contents of the array.
Then, the second line contains $n$ integers $x_1,x_2,…,x_n$: the contents of the array.
Output
Print the minimum number of moves.
Constraints
$1≤n≤2⋅10^5$
$1≤x_i≤10^9$
$1≤x_i≤10^9$
Sample 1 Input
5
3 2 5 1 7
Sample 1 Output
5
第二个数字从 $2$ 变为 $3$,代价为 $3-2=1$。
第四个数字从 $1$ 变成 $5$,代价为 $5-1=4$。
总代价为 $4+1=5$。
第四个数字从 $1$ 变成 $5$,代价为 $5-1=4$。
总代价为 $4+1=5$。