제출 #756730

#제출 시각아이디문제언어결과실행 시간메모리
756730matereGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; int n,a[200005],pref[200005],suf[200005],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]=max((a[i-1]+pref[i-1])-a[i]+1,0); // cout<<pref[i]<<' '; } // cout<<endl; for(int i=n;i>=1;i--){ suf[i]=max((a[i+1]+suf[i+1])-a[i]+1,0); // cout<<suf[i]<<' '; } // cout<<endl; for(int i=0;i<=n;i++){ // cout<<i<<' '<<pref[i]<<' '<<suf[i+1]<<endl; if(a[i]==a[i+1]) ans=min(ans,max(pref[i],suf[i+1])+1); else ans=min(ans,max(pref[i],suf[i+1])); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...