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>
#define ll long long
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,A[500005],B[500005],pre[500005],suf[500005],ans,minn;
int main() {
cin>>n;
for(ll i=1;i<=n;i++) {
cin>>A[i];
}
for(ll i=1;i<=n;i++) {
if(i!=n) B[i]=A[i+1]-A[i];
}
for(ll i=1;i<n;i++) {
pre[i]=pre[i-1];
if(B[i]<=0) pre[i]+=abs(B[i])+1;
}
for(ll i=n-1;i>=1;i--) {
suf[i]=suf[i+1];
if(B[i]>=0) suf[i]+=B[i]+1;
//cout<<B[i]<<"_"<<suf[i]<<" ";
}
//cout<<endl;
minn=1e18;
for(ll i=1;i<=n;i++) {
ans=max(pre[i-1],suf[i]);
//cout<<pre[i-2]<<"_"<<suf[i+1]<<"_"<<ans<<" ";
minn=min(minn,ans);
}
cout<<minn;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |