Submission #756757

#TimeUsernameProblemLanguageResultExecution timeMemory
756757matereGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; long long n,a[200005],pref[200005][2],suf[200005][2],ans=1999999999; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ pref[i][1]=max((a[i-1]+pref[i-1][1])-a[i]+1,0ll); pref[i][0]=pref[i-1][0]+max(pref[i][1]-pref[i-1][1],0ll); // cout<<pref[i][0]<<' '; } // cout<<endl; for(int i=n;i>=1;i--){ suf[i][1]=max((a[i+1]+suf[i+1][1])-a[i]+1,0ll); suf[i][0]=suf[i+1][0]+max(suf[i][1]-suf[i+1][1],0ll); // cout<<suf[i][0]<<' '; } // cout<<endl; for(int i=0;i<=n;i++){ // cout<<i<<' '<<pref[i]<<' '<<suf[i+1]<<endl; if(a[i]+pref[i][1]==a[i+1]+suf[i+1][1]) ans=min(ans,max(pref[i][0],suf[i+1][0])+1); else ans=min(ans,max(pref[i][0],suf[i+1][0])); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...