제출 #974246

#제출 시각아이디문제언어결과실행 시간메모리
974246berrGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
27 ms10324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n), pref(n), suf(n); for(auto &i: a) cin >> i; int ma=a[0]; vector<int> pref_ma(n), suf_ma(n); pref_ma=a, suf_ma=a; for(int i=1; i<n; i++){ pref[i]+=max(0LL, ma+1-(a[i]+pref[i-1])); ma=max(a[i]+pref[i-1], ma+1); pref_ma[i]=ma; pref[i]+=pref[i-1]; } ma=a[n-1]; for(int i=n-2; i>=0; i--){ suf[i]+=max(0LL, ma+1-(a[i]+suf[i+1])); ma=max(a[i]+suf[i+1], ma+1); suf_ma[i]=ma; suf[i]+=suf[i+1]; } int ans=max(pref[0], suf[0]); for(int i=1; i<n; i++){ ans=min(ans, max(pref[i], suf[i])); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...