Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- void solve(){
- int n; cin>>n;
- vector<int> v(n+1);
- for(int i=1; i<=n; i++) cin>>v[i];
- ll ans = 0;
- for(int i=1; i<=n ; i++){
- if(v[i] < v[i-1]) ans += abs(v[i]-v[i-1]);
- }
- cout<<ans<<'\n';
- }
- int main(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int TC = 1;
- // cin>>TC;
- while(TC--){
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment