IMohammedNasr

Day 1 / C

Aug 17th, 2022 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void solve(){
  6.     int n; cin>>n;
  7.     vector<int> v(n+1);
  8.     for(int i=1; i<=n; i++) cin>>v[i];
  9.     ll ans = 0;
  10.     for(int i=1; i<=n ; i++){
  11.         if(v[i] < v[i-1]) ans += abs(v[i]-v[i-1]);
  12.     }
  13.     cout<<ans<<'\n';
  14. }
  15.  
  16.  
  17. int main(){
  18.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);  
  19.     int TC = 1;
  20.     // cin>>TC;
  21.     while(TC--){
  22.         solve();
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment