# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532478 | chenyan | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 23 ms | 3440 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 int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 200010
int a[N],d[N],su,s,ans=1e18;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,i,j;
cin>>n;
for(i=0;i<n;i++) cin>>a[i];
for(i=1;i<n;i++){
d[i]=a[i]-a[i-1];
if(d[i]>=0) su+=d[i]+1;
}
ans=max(su,s);
for(i=1;i<n;i++){
if(d[i]>=0) su-=d[i]+1;
if(d[i]<=0) s+=-d[i]+1;
ans=min(ans,max(su,s));
}
cout<<ans<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |