# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
512801 | jesus_coconut | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 49 ms | 6176 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>
#define pb push_back
#define eb emplace_back
#define all(a) begin(a), end(a)
#define F first
#define S second
using namespace std;
using ll = long long;
vector<ll> prefCost(vector<int> const &v) {
vector<ll> ret(size(v));
int prev = v[0];
for (int i = 1; i < size(ret); ++i) {
ret[i] = ret[i-1] + max(0ll, (ll)v[i-1] + 1 - v[i]);
prev = max(prev + 1, v[i]);
}
return ret;
}
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (auto &it : v) cin >> it;
auto a = prefCost(v);
reverse(all(v));
auto b = prefCost(v);
reverse(all(b));
ll ans = LLONG_MAX;
for (int i = 0; i < n; ++i) {
ans = min(ans, max(a[i], b[i]));
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |