Submission #756715

#TimeUsernameProblemLanguageResultExecution timeMemory
756715dzdzxGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ll n; cin>>n; ll a[n+1],b[n+1]; for (int i=1;i<=n;i++){ cin>>a[i];b[i]=a[i]; } ll pref[n+1],suff[n+1]; pref[1]=0; for (int i=2;i<=n;i++){ pref[i]=max(pref[i-1],a[i-1]+1-a[i]); a[i]=max(a[i-1]+1,a[i]); } suff[n]=0; for (int i=n-1;i>=1;i--){ suff[i]=max(suff[i+1],b[i+1]+1-b[i]); b[i]=max(b[i+1]+1,b[i]); } ll ans=-1; for (int i=1;i<=n;i++){ if (ans==-1)ans=max(suff[i],pref[i]); ans=min(ans,max(suff[i],pref[i])); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...