Submission #1319977

#TimeUsernameProblemLanguageResultExecution timeMemory
1319977b_esma101811Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
70 ms5024 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void solve() { int n; cin >> n; int a[n + 1]; for(int i = 1; i <= n; i++) { cin >> a[i]; } int pref[n + 1]; pref[1] = 0; for(int i = 2; i <= n; i++) { pref[i] = pref[i - 1]; if(a[i - 1] >= a[i]) { pref[i] += (a[i - 1] - a[i] + 1); } } int suf[n + 1]; suf[n] = 0; for(int i = n - 1; i >= 1; i--) { suf[i] = suf[i + 1]; if(a[i + 1] >= a[i]) { suf[i] += (a[i + 1] - a[i] + 1); } } int ans = 1e18; for(int i = 1; i <= n; i++) { ans = min({ans, max(pref[i], suf[i])}); } cout << ans << endl; } signed main(){ int t = 1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...