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 speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
int n;
ll a[MAX];
ll rt[MAX];
int main() {
speed;
cin>>n;
ll last=0;
for (int i=1;i<=n;i++) {
cin>>a[i];
a[i]=a[i]-last;
last+=a[i];
// cout<<a[i]<<" ";
}
// cout<<"\n";
ll ans=oo;
rt[n+1]=0;
for (int i=n;i>=1;i--) {
rt[i]=rt[i+1]+max(0ll,a[i]+1);
}
ll lft=0;
for (int i=1;i<=n+1;i++) {
ans=min(ans,max(lft,rt[i]));
lft+=max(0ll,1-a[i]);
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |