Submission #1006943

#TimeUsernameProblemLanguageResultExecution timeMemory
1006943faqinyeagerGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms408 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; using ll = long long; int n; vector<ll> a, pref, suff; int main(){ cin >> n; a.resize(n); pref.resize(n, 0); suff.resize(n, 0); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 1; i < n; i++) if(a[i - 1] >= a[i]) pref[i] = a[i - 1] - a[i] + 1; for(int i = n - 2; i >= 0; i--) if(a[i] <= a[i + 1]) suff[i] = a[i + 1] - a[i] + 1; //for(int i = 0; i < n; i++) cout << pref[i] << ' '; cout << '\n'; //for(int i = 0; i < n; i++) cout << suff[i] << ' '; cout << "\n\n"; int l = 0, r = n - 1; ll lsum = 0, rsum = 0; while(l <= r){ if(lsum < rsum){ lsum += pref[l]; l++; }else{ rsum += suff[r]; r--; } } cout << max(lsum, rsum); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...