# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
868509 | mgl_diamond | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 22 ms | 6304 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 ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int N = 2e5+5;
int n, a[N];
ll l[N], r[N];
int main() {
setIO();
cin >> n;
foru(i, 1, n) cin >> a[i];
foru(i, 1, n-1) {
l[i] = l[i-1];
int diff = a[i+1] - a[i];
if (diff <= 0) l[i] += 1-diff;
}
ford(i, n-1, 1) {
r[i] = r[i+1];
int diff = a[i+1] - a[i];
if (diff >= 0) r[i] += diff+1;
}
ll ans = 1e18;
foru(i, 0, n-1) {
// cout << l[i] << " " << r[i+1] << "\n";
ans = min(ans, max(l[i], r[i+1]));
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |