# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
649274 | milisav | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 30 ms | 6252 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>
#define maxn 300000
using namespace std;
int n;
int a[maxn];
long long pref[maxn];
long long suf[maxn];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
}
for(int i=2;i<=n;i++) {
pref[i]=pref[i-1];
if(a[i]<=a[i-1]) pref[i]+=(a[i-1]-a[i]+1);
}
for(int i=n-1;i>=1;i--) {
suf[i]=suf[i+1];
if(a[i]<=a[i+1]) suf[i]+=(a[i+1]-a[i]+1);
}
long long ans=1e18;
for(int i=1;i<=n;i++) {
ans=min(ans,max(pref[i],suf[i]));
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |