AtCoder Beginner Contest 176
C
Step
AtCoder
⌀ 0
原题
← BD →
翻译中…

Problem Statement

翻译中…

$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.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2\times 10^5$
  • $1 \leq A_i \leq 10^9$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 \ldots A_N

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
5
2 1 5 4 3
Output #1
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.
Input #2
5
3 3 3 3 3
Output #2
0
Giving a stool of height $0$ to everyone will work.
题目信息
题号
abc176_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。