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 <iostream>
#include <fstream>
using namespace std;
const int nmax=2e5+5;
long long int n, v[nmax], dist[nmax], pre[nmax], suf[nmax];
int main()
{
cin >> n;
for (int i=1;i<=n;i++)
{
cin >> v[i];
dist[i]=v[i]-v[i-1];
}
long long ret=1e18;
for (int i=1;i<=n;i++)
{
pre[i]=pre[i-1];
if (dist[i]<=0)
{
pre[i]+=(-dist[i])+1;
}
}
for (int i=n;i>=1;i--)
{
suf[i]=suf[i+1];
if (dist[i+1]>=0)
{
suf[i]+=dist[i+1]+1;
}
}
for (int i=1;i<=n;i++)
{
ret=min (ret, max (1ll*pre[i], 1ll*suf[i]));
}
cout << ret;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |