Submission #964344

#TimeUsernameProblemLanguageResultExecution timeMemory
964344maxFedorchukGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
21 ms7232 KiB
#include <bits/stdc++.h> using namespace std; const long long MX=2e5+10; const long long INF=1e18; long long a[MX],pr[MX],syf[MX]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); long long n; cin>>n; for(long long i=1;i<=n;i++) { cin>>a[i]; } for(long long i=2;i<=n;i++) { pr[i]=pr[i-1]+max(0LL,a[i-1]+1-a[i]); } for(long long i=n-1;i>=1;i--) { syf[i]=syf[i+1]+max(0LL,a[i+1]+1-a[i]); } long long ans=INF; for(long long i=1;i<=n;i++) { ans=min(ans,max(pr[i],syf[i])); } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...