Submission #935375

#TimeUsernameProblemLanguageResultExecution timeMemory
935375weakweakweakGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n, a[310000]; ll pre[310000] = {0}, suf[310000] = {0}; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = a[n + 1] = -1; for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1]; if (a[i] <= a[i - 1]) pre[i] += a[i - 1] + 1 - a[i]; } for (int i = n; i >= 1; i--) { suf[i] = suf[i + 1]; if (a[i] <= a[i + 1]) suf[i] += a[i + 1] + 1 - a[i]; } ll ans = min(pre[n], suf[1]); for (int i = 1; i <= n; i++) ans = min(ans, max(pre[i - 1], suf[i])); cout << ans << '\n'; return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...