# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
679948 | redstonegamer22 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 0 ms | 212 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;
#define int long long
int32_t main() {
int n; cin >> n;
vector<int> a(n); for(auto &e : a) cin >> e;
int watered = 0;
int l = 1, r = n - 2;
while(l < r) {
// cerr << l << " " << r << " " << watered << endl;
while(l <= r && a[l] + watered > a[l - 1]) {
a[l] += watered; l += 1;
}
while(r >= l && a[r] + watered > a[r + 1]) {
a[r] += watered; r -= 1;
}
// cerr << l << " " << r << " " << watered << endl;
if(r < l) break;
// cerr << a[l - 1] << " " << a[l] << " " << a[r + 1] << " " << a[r] << endl;
int next = min(a[l - 1] - (a[l] + watered) + 1, a[r + 1] - (a[r] + watered) + 1);
watered += next;
}
for(int i = 0; i + 1 < a.size(); i++) if(a[i] == a[i + 1]) watered += 1;
cout << watered << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |