Submission #1280411

#TimeUsernameProblemLanguageResultExecution timeMemory
1280411hoangtien69Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
1 ms572 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; #define int long long int n; int a[MAXN]; int pre[MAXN]; int suf[MAXN]; int ans_pre[MAXN]; int ans_suf[MAXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int last = -1; for (int i = 1; i <= n; i++) { int cur = last + 1; if (a[i] >= cur) { pre[i] = 0; last = a[i]; } else { pre[i] = cur - a[i]; last = cur; } } last = -1; for (int i = n; i >= 1; i--) { int cur = last + 1; if (a[i] >= cur) { suf[i] = 0; last = a[i]; } else { suf[i] = cur - a[i]; last = cur; } } for (int i = 1; i <= n; i++) { ans_pre[i] = max(ans_pre[i - 1], pre[i]); } for (int i = n; i >= 1; i--) { ans_suf[i] = max(ans_suf[i + 1], suf[i]); } int ans = LLONG_MAX; for (int i = 1; i < n; i++) { ans = min(ans, ans_pre[i - 1] + ans_suf[i]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...