제출 #372222

#제출 시각아이디문제언어결과실행 시간메모리
372222dolphingarlicGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
33 ms5120 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll a[200002], pref[200002], suff[200002]; int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + max(0ll, a[i - 1] - a[i] + 1); for (int i = n; i; i--) suff[i] = suff[i + 1] + max(0ll, a[i + 1] - a[i] + 1); ll ans = LLONG_MAX; for (int i = 1; i < n; i++) ans = min(ans, max(pref[i], suff[i + 1]) + (a[i] + pref[i] == a[i + 1] + suff[i + 1])); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...