# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585891 | krit3379 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 1 ms | 340 KiB |
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 N 200005
int a[N],dp1[N],dp2[N],ans=2e9;
int main(){
int n,i,ma;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&a[i]);
ma=0;
for(i=1;i<=n;i++){
ma=max(ma,a[i]-i);
dp1[i]=ma-a[i]+i;
dp1[i]=max(dp1[i],dp1[i-1]);
}
ma=0;
for(i=n;i;i--){
ma=max(ma,a[i]+i);
dp2[i]=ma-a[i]-i;
dp2[i]=max(dp2[i],dp2[i+1]);
}
for(i=1;i<=n;i++)ans=min(ans,max(dp1[i],dp2[i]));
printf("%d",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |