Submission #414864

#TimeUsernameProblemLanguageResultExecution timeMemory
414864vato_chachanidzeGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
21 ms332 KiB
#include<bits/stdc++.h> using namespace std; long long n,k,i,a[1000009],ans,Final_ans,q,q2,b[1000009]; int main() { cin>>n; for(k=1;k<=n;k++) { cin>>a[k]; b[k]=a[k]; } Final_ans=-1; for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { a[i]=b[i]; } for(i=1;i<=k-1;i++) { if(a[i]>=a[i+1]) { q2=q; if(a[i+1]+q>a[i]) { a[i+1]+=q; } else { a[i+1]+=q2; q+=a[i]+1-a[i+1]; ans+=a[i]+1-a[i+1]; a[i+1]=a[i]+1; } } else { q=0; } } for(i=k;i<=n;i++) { a[i]+=q; if(a[i]<a[i+1]) { break; } } q=0; for(i=n;i>=k+1;i--) { if(a[i]>=a[i-1]) { q2=q; if(a[i-1]>a[i]-q) { a[i-1]+=q; } else { a[i-1]+=q2; q+=a[i]+1-a[i-1]; ans+=a[i]+1-a[i-1]; a[i-1]=a[i]+1; } } else { q=0; } } if(Final_ans==-1) { Final_ans=ans; } Final_ans=min(Final_ans,ans); ans=0; q=0; } cout<<Final_ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...