제출 #371017

#제출 시각아이디문제언어결과실행 시간메모리
371017valerikkGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
34 ms6656 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; n += 2; vector <ll> a(n); a[0] = a[n - 1] = 0; for (int i = 1; i < n - 1; i++) cin >> a[i]; vector <ll> d(n); for (int i = 1; i < n; i++) d[i] = a[i] - a[i - 1]; vector <ll> pref(n - 1); for (int i = 0; i < n - 1; i++) { pref[i] = max(0ll, -d[i + 1] + 1); if (i != 0) pref[i] += pref[i - 1]; } vector <ll> suf(n - 1); for (int i = n - 2; i >= 0; i--) { suf[i] = max(0ll, d[i + 1] + 1); if (i != n - 2) suf[i] += suf[i + 1]; } ll ans = 1e18; for (int i = 0; i < n - 2; i++) ans = min(ans, max(pref[i], suf[i + 1])); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...