제출 #756740

#제출 시각아이디문제언어결과실행 시간메모리
756740dzdzxGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
99 ms8412 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(0ll,a[i-1]+1-a[i])+pref[i-1]; } suff[n]=0; for (int i=n-1;i>=1;i--){ suff[i]=max(0ll,b[i+1]+1-b[i])+suff[i+1]; } 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...