Submission #1014679

#TimeUsernameProblemLanguageResultExecution timeMemory
1014679snpmrnhlolGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
54 ms7048 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 2e5; const ll inf = 1e18; ll v[N],v2[N],v3[N]; int main(){ ll n; ll ans = inf; cin>>n; for(ll i = 0;i < n;i++){ cin>>v[i]; } for(ll i = 1;i < n;i++){ v2[i] = v2[i - 1] + max(0ll,v[i - 1] - v[i] + 1); } for(ll i = n - 2;i >= 0;i--){ v3[i] = v3[i + 1] + max(0ll,v[i + 1] - v[i] + 1); } for(ll i = 0;i < n;i++){ ans = min(ans,max(v2[i],v3[i])); } cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...