제출 #1319989

#제출 시각아이디문제언어결과실행 시간메모리
1319989vuqar_bazarov1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
25 ms5064 KiB
/* * * author: attacker * * created: 04.02.2026 18:39:36 */ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif #define mt_rng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int64_t> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int64_t> pref(n); pref[0] = 0; for (int i = 1; i < n; i++) { if (a[i] <= a[i - 1]) { pref[i] = pref[i - 1] + a[i - 1] + 1 - a[i]; } else { pref[i] = pref[i - 1]; } } vector<int64_t> suff(n); suff[n - 1] = 0; for (int i = n - 2; i >= 0; i--) { if (a[i] <= a[i + 1]) { suff[i] = suff[i + 1] + a[i + 1] + 1 - a[i]; } else { suff[i] = suff[i + 1]; } } int64_t res = int64_t(1e18); for (int i = 0; i < n; i++) { res = min(res, max(pref[i], suff[i])); } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...