This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define endl "\n"
#define out(x) cout<< #x << " = " << x << endl
ll arr[200005], dif[200005];
int n;
signed main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for (int i=1;i<=n;i++) cin>>arr[i];
for (int i=2;i<=n;i++) dif[i] = arr[i] - arr[i-1];
ll left = 0, right = 0;
for (int i=2;i<=n;i++) if (dif[i] >= 0) right += dif[i]+1;
ll best = max(left, right);
for (int i=2;i<=n;i++){
ll orig = dif[i]>=0 ? dif[i]+1 : 0;
ll _new = dif[i]<=0 ? 1-dif[i] : 0;
left += _new;
right -= orig;
best = min(best, max(left,right));
}
cout<<best<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |