Submission #855789

#TimeUsernameProblemLanguageResultExecution timeMemory
855789annabeth9680Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
24 ms7004 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; vector<int> arr(N); for(int i = 0;i<N;++i) cin >> arr[i]; vector<int> pref(N),suf(N); pref[0] = 0; for(int i = 1;i<N;++i){ pref[i] = pref[i-1]+max(arr[i-1]-arr[i]+1,(int)0); } suf[N-1] = 0; for(int i = N-2;i>=0;--i){ suf[i] = suf[i+1]+max(arr[i+1]-arr[i]+1,(int)0); } int ans = (int)(1e18); for(int i = 0;i<N;++i){ //cout << suf[i] << " " << pref[i] << "\n"; ans = min(ans,max(suf[i],pref[i])); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...