Problem5307--ABC176——Task C:Step

5307: ABC176——Task C:Step

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

$N$ persons are standing in a row. The height of the $i$-th person from the front is $A_i$.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.
Find the minimum total height of the stools needed to meet this goal.
$N$ 个人排队,第  $i$ 个人的身高记为 $A_i$。
我们每个人站在一个小板凳,这个小板凳的高度可以为 $0$。这样以下的条件可以满足每一个人:
一个人前面的人身高不会超过自己,一个人的身高包括小板凳的高度。 
为了达到这个目标,请找出所有小板凳总和的最小值。

Input

Input is given from Standard Input in the following format:
$N$
$A_1 \cdots \ A_N$

Output

Print the minimum total height of the stools needed to meet the goal.

Constraints

$1≤N≤2×10^5$
$1≤A_i≤10^9$

Sample 1 Input

5
2 1 5 4 3

Sample 1 Output

4
If the persons stand on stools of heights $0,\ 1,\ 0,\ 1$, and $2$, respectively, their heights will be $2,\ 2,\ 5,\ 5$, and $5$, satisfying the condition.
We cannot meet the goal with a smaller total height of the stools.

Sample 2 Input

5
3 3 3 3 3

Sample 2 Output

0

HINT

题目来源: AtCoder Beginner Contest 176 C题

Source/Category

C++语法 1.4.循环结构