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;
int main(){
int n;
cin >> n;
long long int arr[n],brr[n-1];
for(int i=0;i<n;i++){
cin >> arr[i];
if(i>0){
brr[i-1]=arr[i]-arr[i-1];
}
}
long long int crr[n],drr[n];
crr[0]=0;
drr[n-1]=0;
for(int i=1;i<n;i++){
crr[i]=crr[i-1]+max(1-brr[i-1],0LL);
}
for(int i=n-2;i>=0;i--){
drr[i]=drr[i+1]+max(1+brr[i],0LL);
}
long long int ans=1000000000000000000;
for(int i=0;i<=n-1;i++){
ans=min(ans,max(crr[i],drr[i]));
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |