Submission #469309

#TimeUsernameProblemLanguageResultExecution timeMemory
469309vincent97198Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
129 ms6908 KiB
#include<bits/stdc++.h> #define int long long #define double long double using namespace std; const double eps=1e-6; int32_t main() { int n; cin >> n; vector<int> h(n+1),L(n+2,0),R(n+2,0); for(int i=1;i<=n;++i) cin >> h[i]; for(int i=n;i>=1;--i){ R[i]=R[i+1]; if(i+1<=n && h[i+1]>=h[i]) R[i]+=h[i+1]-h[i]+1; } for(int i=1;i<=n;++i){ L[i]=L[i-1]; if(i-1>=1 && h[i-1]>=h[i]) L[i]+=h[i-1]-h[i]+1; } int ans=1e18; for(int i=1;i<=n;++i){ /* int tmpL=0,tmpR=0; if(i-1>=1 && h[i]+R[i+1]<=h[i-1]) tmpL=h[i-1]-(h[i]+R[i+1])+1; if(i+1<=n && h[i]+L[i-1]<=h[i+1]) tmpR=h[i+1]-(h[i]+L[i-1])+1; ans=min(ans,R[i+1]+L[i-1]+tmpL+tmpR); */ ans=min(ans,max(L[i],R[i])); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...