Submission #931930

#TimeUsernameProblemLanguageResultExecution timeMemory
931930AiperiiiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back using namespace std; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n;cin>>n; vector <int> a(n+1),pr(n+1),sf(n+1); for(int i=1;i<=n;i++)cin>>a[i]; a.pb(0); int mn=1e18; for(int j=1;j<=n;j++){ pr[j]=pr[j-1]+max(0ll,a[j-1]-a[j]+1); } for(int j=n;j>=1;j--){ sf[j]=sf[j+1]+max(0ll,a[j+1]-a[j]+1); } for(int i=1;i<=n;i++){ mn=min(mn,max(pr[i],sf[i])); } cout<<mn<<"\n"; } /* 5 3 2 2 3 1 5 9 7 5 3 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...