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;
pair<ll,ll> r[212345],l[212345];
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n,c=0;
cin>>n;
ll a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n-2;i>=0;i--){
if(a[i]<=a[i+1]+r[i+1].second){
r[i].second+=(a[i+1]+r[i+1].second)-a[i]+1;
r[i].first=r[i].second+r[i+1].first-r[i+1].second;
}
}
for(int i=1;i<n;i++){
if(a[i]<=a[i-1]+l[i-1].second){
l[i].second=max(0ll,(a[i-1]+l[i-1].second)-a[i]+1);
l[i].first=l[i-1].first+max(0ll,l[i].second-l[i-1].second);
}
}
for(int i=0;i<n;i++){
c=max(c,l[i].first+r[i].first-min(r[i].second,l[i].second));
}
cout<<c;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |