aboutsummaryrefslogtreecommitdiff
path: root/cses/IncreasingArray/main.cpp
blob: 67f6afec461257bdcb8ab3012b9e278dd774d178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>

using namespace std;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  int n;
  cin >> n;
  int mx = 0;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    mx = max(mx , x);
    ans += max(mx - x, 0);
  }
  cout << ans << "\n";
}