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;
typedef long long ll;
const int MX=2e5+5;
int N;
ll A[MX], B[MX], C[MX], pf[MX], sf[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N;
for(int i=1;i<=N;i++) {
cin>>A[i];
B[i]=A[i]-A[i-1];
}
B[N+1]=A[N+1]-A[N];
for(int i=1;i<=N+1;i++) {
pf[i]+=pf[i-1];
if(B[i]<=0)
pf[i]+=1-B[i];
}
for(int i=N;i>=1;i--) {
sf[i]+=sf[i+1];
if(B[i+1]>=0)
sf[i]+=B[i+1]+1;
}
ll ans=pf[N];
for(int i=1;i<=N;i++) {
ans=min(ans,max(pf[i],sf[i]));
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |