제출 #1217359

#제출 시각아이디문제언어결과실행 시간메모리
1217359maomaoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
14 ms4348 KiB
#include <iostream> using namespace std; #define ll long long #define fori(n) for(int i=1;i<=n;i++) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int n; cin >> n; const int m = 200005; int h[m];h[0]=0; fori(n) cin >> h[i]; //precompute the cost so far if chose (i,n+1-i) ll pre[m] = {0}; for(int i=2;i<=n;i++) pre[i] = pre[i-1] + max(0,h[i-1]-h[i]+1); ll suf[m] = {0}; for(int i=n-1;i>=1;i--) suf[i] = suf[i+1] + max(0,h[i+1]-h[i]+1); ll ans = min(pre[n],suf[1]); fori(n-1) ans = min(ans,max(pre[i],suf[i])); //max pre[i] suf[i] to water range(i,n+1-i) and suffice both ends cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...