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 <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn = 2e5+10;
ll arr[mxn],diff[mxn],pref[mxn],suf[mxn];
int main(){
int n;
cin>>n;
for(int i = 1;i<=n;i++){
cin>>arr[i];
if(i>1)diff[i] = arr[i]-arr[i-1];
}
for(int i = 2;i<=n;i++){
pref[i] = pref[i-1]+(diff[i]<=0?1-diff[i]:0);
}
for(int i = n;i>=1;i--){
suf[i] = suf[i+1]+(diff[i]>=0?diff[i]+1:0);
}
ll ans = 1e9+10;
for(int i = 2;i<=n+1;i++){
ans = min(ans,max(pref[i-1],suf[i]));
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |