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;
ll plant_vegetables(vector<ll> nums) {
int n = nums.size();
vector<ll> le(n), ri(n), rel(n), rer(n);
rel[0] = nums[0];
rer[n-1] = nums[n-1];
for(int i = 1; i < n; i++) {
le[i] = le[i-1] + max(0LL, nums[i-1] - nums[i] + 1);
rel[i] = max(nums[i], nums[i-1]+1);
}
for(int i = n-2; i >= 0; i--) {
ri[i] = ri[i+1] + max(0LL, nums[i+1] - nums[i] + 1);
rer[i] = max(nums[i], nums[i+1]+1);
}
ll ans = 1234567891234567890;
for(int i = 0; i < n; i++) {
ans = min(ans, max(le[i], ri[i]));
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<ll> nums(n);
for(int i = 0; i < n; i++) cin >> nums[i];
cout << plant_vegetables(nums) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |