제출 #935394

#제출 시각아이디문제언어결과실행 시간메모리
935394weakweakweakGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
20 ms6508 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++) { // cout << pre[i] << ' ' << suf[i] << '\n'; ans = min(ans, max(pre[i], suf[i])); } cout << ans << '\n'; return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...