Increasing Array
One move increases any element by 1. Print the minimum total moves to make the array non-decreasing.
Input: the first line has N; the second line has N integers.
Output: the minimum number of +1 moves.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ ai ≤ 109
Sample Tests
Input 1
5 3 2 5 1 7
Output 1
5
Input 2
2 2 2
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.