Advertisement
Salehisayev

BAX

Mar 8th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. #define pii pair<int , int>
  6. #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  7. #define MAXX 200005
  8.  
  9. ll max(ll a , ll b){
  10. if(a > b) return a;
  11. else return b;
  12. }
  13.  
  14. ll a[MAXX];
  15. ll n , cvb;
  16.  
  17. int main()
  18. {
  19. _FastIO;
  20. cin >> n;
  21. for(ll i = 0; i < n; i++){
  22. cin >> a[i];
  23. }
  24. for(ll i = 1; i < n; i++){
  25. cvb += max(0 , a[i - 1] - a[i]);
  26. a[i] = max(a[i] , a[i - 1]);
  27. }
  28. cout << cvb << endl;
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement