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;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const ll INF=3e18;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
ll a[200005],b[200005],suf[200005];
signed main()
{
MottoHayaku
ll n;
cin>>n;
rep1(i,n)
{
cin>>a[i];
b[i]=a[i]-a[i-1];
}
for(int i=n;i>=1;i--)
{
suf[i]=suf[i+1]+max(0LL,b[i]+1);
}
ll ans=INF,cur=0;
rep(i,n+1)
{
ans=min(ans,max(cur,suf[i+1]));
cur+=max(0LL,1-b[i+1]);
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |