#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
//start here
int N;
cin >> N;
vector<int> v(N);
for(auto &i:v)cin >> i;
vector<int> diff;
for(int i = 1;i < N;i++){
diff.push_back(v[i]-v[i-1]);
}
// for(auto i:diff)cout << i << " ";cout << endl;
int front = 0;
int back = 0;
for(auto i:diff){
back += max(0LL,i-(-1));
}
int minAns = back;
for(auto i:diff){
back -= max(0LL,i-(-1));
front += max(0LL,1-i);
// cout << back << " " << front << " " << max(back,front) << endl;
minAns = min(minAns,max(back,front));
// cout << minAns << endl;
}
cout << minAns;
}
/*
8
12 2 34 85 4 91 29 85
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |