Submission #414853

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