제출 #1109465

#제출 시각아이디문제언어결과실행 시간메모리
1109465DobromirAngelovGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
2 ms2552 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN=2e5+5; const long long INF=1e18+5; int n; int a[MAXN]; int l[MAXN], r[MAXN]; long long pref[MAXN], suff[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=2;i<=n;i++) l[i]=max(0, a[i-1]-a[i]+1); for(int i=n-1;i>=1;i--) r[i]=max(0, a[i+1]-a[i]+1); for(int i=2;i<=n;i++) pref[i]=pref[i-1]+l[i]; for(int i=n-1;i>=1;i--) suff[i]=suff[i+1]+r[i]; long long ans=INF; for(int i=1;i<=n;i++) { long long cur=max(pref[i-1],suff[i+1]); long long need=max(l[i]-suff[i+1], r[i]-pref[i-1]); if(need>0) cur+=need; ans=min(ans, cur); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...