제출 #658856

#제출 시각아이디문제언어결과실행 시간메모리
658856GrandTiger1729Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
32 ms10104 KiB
#include <iostream> #include <vector> using namespace std; const long long INF = 1e18; int main(){ cin.tie(0)->sync_with_stdio(0); int n; cin >> n; vector<long long> a(n + 2); for (int i = 1; i <= n; i++){ cin >> a[i]; } auto b = a; long long pref[n + 2]{}; for (int i = 1; i <= n; i++){ pref[i] = pref[i - 1] + max(a[i], a[i - 1] + 1) - a[i]; b[i] = max(b[i], b[i - 1] + 1); } auto c = a; long long suff[n + 2]{}; for (int i = n; i >= 1; i--){ suff[i] = suff[i + 1] + max(a[i], a[i + 1] + 1) - a[i]; c[i] = max(c[i], c[i + 1] + 1); } long long ans = INF; for (int i = 0; i <= n; i++){ long long res = max(pref[i], suff[i + 1]) + (pref[i] == suff[i + 1] && b[i] == c[i + 1]); ans = min(ans, res); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...