제출 #503336

#제출 시각아이디문제언어결과실행 시간메모리
503336WongChun1234Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms332 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=200050; int n,a[MAXN],frnt[MAXN],bck[MAXN],curr,cb=INT_MAX; int main(){ cin>>n; for (int i=1;i<=n;i++) cin>>a[i]; curr=a[1]; for (int i=2;i<=n;i++){ if (curr+1>a[i]+frnt[i-1]){ curr++; frnt[i]=max(frnt[i-1],curr-a[i]); }else{ curr=a[i]+frnt[i-1]; frnt[i]=frnt[i-1]; } } curr=a[n]; for (int i=n-1;i>=1;i--){ if (curr+1>a[i]+bck[i+1]){ curr++; bck[i]=max(bck[i+1],curr-a[i]); }else{ curr=a[i]+bck[i+1]; bck[i]=bck[i+1]; } } for (int i=1;i<=n;i++) cb=min(cb,max(frnt[i],bck[i])); cout<<cb<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...