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