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>
using namespace std;
long long n,a[200010],st[200010],dr[200010],ans=100000000000000000;
int main()
{
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a[i];
st[i]=st[i-1];
if(a[i-1]>=a[i])
st[i]+=a[i-1]-a[i]+1;
}
for(int i=n;i>=1;--i)
{
dr[i]=dr[i+1];
if(a[i+1]>=a[i])
dr[i]+=a[i+1]-a[i]+1;
}
for(int i=1;i<=n;++i)
ans=min(ans,max(st[i],dr[i]));
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |