# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854101 | ancuber1031 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 1 ms | 504 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.
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define p_q priority_queue
#define endl '\n'
#define pb push_back
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n; cin>>n;
vector<int> a(n+2);
vector<int> dp1(n+2), dp2(n+2), lk1(n+2), lk2(n+2), h1(n+2), h2(n+2), mx1(n+2), mx2(n+2);
for (int i = 1; i <= n; ++i) cin>>a[i];
dp1[1] = lk1[1] = dp2[n] = lk2[n] = 0;
h1[1] = a[1];
h2[n] = a[n];
for (int i = 2; i <= n; ++i) {
h1[i] = max(a[i],h1[i-1]+1);
lk1[i] = max(h1[i]-a[i],0ll);
dp1[i] = dp1[i-1]+max(0ll,lk1[i]-mx1[i-1]);
mx1[i] = max(mx1[i-1],lk1[i]);
//cout<<lk1[i]<<' '<<dp1[i]<<' '<<h1[i]<<endl;
}
for (int i = n-1; i > 0; --i) {
h2[i] = max(a[i],h2[i+1]+1);
lk2[i] = max(h2[i]-a[i],0ll);
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |