Submission #530314

#TimeUsernameProblemLanguageResultExecution timeMemory
530314soondro2266Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms332 KiB
#include<bits/stdc++.h> using namespace std; #define int long long vector<int> arr; int n; int check(int idx){ vector<int> akr = arr; int a = 0,b = 0; for(int i = 1; i <= idx; i++){ if(akr[i-1] >= akr[i]){ a += akr[i-1]+1-akr[i]; } } for(int i = n-1; i > idx; i--){ if(akr[i-1] <= akr[i]){ b += akr[i]+1-akr[i-1]; } } return max(a,b); } signed main(){ cin >> n; for(int i = 0,tmp; i < n; i++){ cin >> tmp; arr.push_back(tmp); } /*for(int i = 0; i < n;i++){ cout << check(i) << " "; } cout << endl;*/ int l = 0, r = n-1,mid,a,b,c; while(1){ if(r-l <= 4){ break; } mid = (l+r)/2; a = check(mid); b = check(mid+1); c = check(mid-1); if(a < b && a < c){ cout << a << endl; return 0; } else if(a < b){ r = mid-1; } else{ l = mid+1; } } int ans = 1e18; for(int i = l; i <= r; i++){ ans = min(ans,check(i)); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...