#CCBCHBAHAI0000109. Increasing Array
Increasing Array
Increasing Array
Source: CSES
Version: Phuoc Hung OJ Extended
Problem
Given , one move increases one chosen element by 1. Find the minimum number of moves needed to make the array nondecreasing, i.e. for every .
Input
The first line contains . The second line contains .
Output
Print the minimum number of moves; use a 64-bit accumulator.
Subtask
Subtask 1 (20 points): , .
Subtask 2 (30 points): , .
Subtask 3 (50 points): , .
Example
Input
5
3 2 5 1 7
Output
5
Explanation
Raise 2 to 3 (1 move) and 1 to 5 (4 moves), for 5 moves total.