Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define all(c) c.begin(),c.end()
- using namespace std;
- typedef long long ll;
- const ll INF64 = 1e18 + 1337;
- const int INF32 = 1e9 + 228;
- const int MOD = 1e9 + 7;
- int n;
- ll a[50000];
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifndef __WIN32
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- #endif
- cin.tie(0);cout.tie(0);
- cin >> n;
- for(int i = 0; i < n; i++)
- cin >> a[i];
- ll ans = 0;
- for(int i = 0; i < n - 1; i++)
- {
- if(a[i] >= a[i + 1])
- {
- int ind = i;
- while( i < n - 1 && a[i] >= a[i + 1] ) i++;
- ans += a[ind] - a[i];
- }
- }
- bool ok = 1;
- for(int i = 0; i < n - 1; i++) if(a[i] >= a[i + 1]) ok = 0;
- if(ok)
- {
- ll maxi = a[0] - a[1];
- for(int i = 0; i < n - 1; maxi = max(maxi, a[i] - a[i+1]), i++);
- cout << maxi;
- return 0;
- }
- cout << ans;
- #ifndef __WIN32
- cin.close();
- cout.close();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement