Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define pii pair<int , int>
- #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define MAXX 200005
- ll max(ll a , ll b){
- if(a > b) return a;
- else return b;
- }
- ll a[MAXX];
- ll n , cvb;
- int main()
- {
- _FastIO;
- cin >> n;
- for(ll i = 0; i < n; i++){
- cin >> a[i];
- }
- for(ll i = 1; i < n; i++){
- cvb += max(0 , a[i - 1] - a[i]);
- a[i] = max(a[i] , a[i - 1]);
- }
- cout << cvb << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement