# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055256 | manhlinh1501 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 19 ms | 5108 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 oo64 = 1e18;
using pll = pair<i64, i64>;
const int MAXN = 2e5 + 5;
int N;
i64 a[MAXN];
i64 prefix[MAXN];
i64 suffix[MAXN];
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
for(int i = 1; i <= N; i++) prefix[i] = prefix[i - 1] + max(0LL, (a[i - 1] + 1) - a[i]);
for(int i = N; i >= 1; i--) suffix[i] = suffix[i + 1] + max(0LL, (a[i + 1] + 1) - a[i]);
i64 ans = oo64;
for(int i = 1; i <= N; i++) ans = min(ans, max(prefix[i], suffix[i]));
cout << ans;
return (0 ^ 0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |