Submission #658653

#TimeUsernameProblemLanguageResultExecution timeMemory
658653Darren0724Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
24 ms6996 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(),x.end() int INF=1e18; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<int> v(n+2); for(int i=1;i<=n;i++){ cin>>v[i]; } vector<int> pre(n+2),suf(n+2); for(int i=1;i<=n;i++){ int t=max((int)0,v[i-1]+1-v[i]); pre[i]=pre[i-1]+t; } for(int i=n;i>=1;i--){ int t=max((int)0,v[i+1]+1-v[i]); suf[i]=suf[i+1]+t; } int ans=INF; for(int i=1;i<=n;i++){ ans=min(ans,max(pre[i],suf[i])); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...