Problems > Increasing Array

Increasing Array

Difficulty: 1100 3000 ms 128 MB

greedy

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.