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 n,v[200005],ans=1e18,a[200005],toneg[200005],topos[200005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
n++;
for(int i=1;i<=n;i++)
v[i]=a[i]-a[i-1];
for(int i=n;i>=1;i--)
{
toneg[i]=toneg[i+1];
if(v[i]>=0)
toneg[i]+=v[i]+1;
}
for(int i=1;i<=n;i++)
{
topos[i]=topos[i-1];
if(v[i]<=0)
topos[i]+=abs(v[i])+1;
}
for(int i=1;i<n;i++)
{
ll val=max(topos[i],toneg[i+1]);
ans=min(ans,val);
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |