Submission #1027116

#TimeUsernameProblemLanguageResultExecution timeMemory
1027116aykhnGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
17 ms7256 KiB
#include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F #define int long long const int MXN = 2e5 + 5; int n; int a[MXN]; int p[MXN], s[MXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = -inf, a[n + 1] = -inf; for (int i = 1; i <= n; i++) p[i] = p[i - 1] + max(0LL, a[i - 1] + 1 - a[i]); for (int i = n; i >= 1; i--) s[i] = s[i + 1] + max(0LL, a[i + 1] + 1 - a[i]); int res = inf; for (int i = 1; i <= n; i++) res = min(res, max(p[i - 1], s[i + 1]) + max(0LL, max(a[i - 1], a[i + 1]) + 1 - a[i])); cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...