Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define bigdata ios::sync_with_stdio(false);cin.tie(nullptr)
- using namespace std;
- typedef long long ll;
- const int INF = 1E9 + 7;
- int n;
- vector<int> a;
- int main(){
- bigdata;
- cin >> n;
- a.resize(n);
- int maxpoint = 0;
- int maxh = 0;
- for (int i = 0; i < n; ++i){
- int tmp;
- cin >> tmp;
- a[i] = tmp;
- if (tmp > maxh){
- maxh = tmp;
- maxpoint = i;
- }
- }
- int curmax = 0;
- int left = 0;
- for (int i = 0; i < maxpoint; ++i){
- if (a[i] >= curmax){
- curmax = a[i];
- }
- else{
- left += curmax - a[i];
- }
- }
- int right = 0;
- curmax = 0;
- for (int i = n - 1; i > maxpoint; --i){
- if (a[i] >= curmax){
- curmax = a[i];
- }
- else{
- right += curmax - a[i];
- }
- }
- cout << left + right;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement