Submission #931928

#TimeUsernameProblemLanguageResultExecution timeMemory
931928AiperiiiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
40 / 100
1079 ms6340 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); for(int i=1;i<=n;i++)cin>>a[i]; a.pb(0); int mn=1e18; for(int i=1;i<=n;i++){ int pr=0,sf=0; for(int j=1;j<=i;j++){ pr+=max(0ll,a[j-1]-a[j]+1); } for(int j=n;j>=i;j--){ sf+=max(0ll,a[j+1]-a[j]+1); } mn=min(mn,max(pr,sf)); } 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...