# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
921381 | TAhmed33 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++98 | 1 ms | 2396 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;
typedef long long ll;
const int MAXN = 2e5 + 25;
ll a[MAXN], n, pref[MAXN], suff[MAXN];
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n; ll x;
for (int i = 1; i <= n; i++) {
ll y; cin >> y;
a[i] = y - x; x = y;
}
for (int i = 2; i <= n; i++) {
pref[i] = max(0ll, 1 - a[i]) + pref[i - 1];
}
for (int i = n; i >= 2; i--) {
suff[i] = max(0ll, a[i] + 1) + suff[i + 1];
}
ll mn = 1e18;
for (int i = 2; i <= n; i++) {
mn = min(mn, max(pref[i], suff[i + 1]));
}
cout << mn << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |