Submission #1218301

#TimeUsernameProblemLanguageResultExecution timeMemory
1218301jellybeanGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
17 ms1864 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define dd(x) cout<<#x<<" is "<<x<<endl; typedef pair<int,int> pii; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; int a[n+2]= {}; for(int i=1; i<=n; i++) cin>>a[i]; int ans = LLONG_MAX; int x=0, y=0; for(int i=1; i<=n; i++){ if(a[i] <= a[i+1]) y+= (a[i+1]-a[i]+1); } ans = y; for(int k=2; k<=n; k++){ //k is the tallest guy if(a[k]>=a[k-1]) y -= (a[k]-a[k-1] +1); if(a[k] <= a[k-1]) x += (a[k-1]-a[k] +1); ans = min(ans,max(x,y)); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...