1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #include <bits/stdc++.h> #define int long long #define N 200005 #define IOS ios::sync_with_stdio(0),cin.tie(0) using namespace std; int n,arr[N]; signed main(){ IOS; cin>>n; for(int i=0;i<n;i++)cin>>arr[i]; int ans = 0; for(int i=1;i<n;i++){ if(arr[i] < arr[i-1]){ ans += arr[i-1] - arr[i]; arr[i] = arr[i-1]; } } cout<<ans<<"\n"; }
|