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;
long long n,k,i,a[1000009],ans,Final_ans,q,q2;
int main()
{
cin>>n;
for(k=1;k<=n;k++)
{
cin>>a[k];
}
Final_ans=-1;
for(k=1;k<=n;k++)
{
for(i=1;i<=k-1;i++)
{
if(a[i]>=a[i+1])
{
q2=q;
if(a[i+1]+q>a[i])
{
a[i+1]+=q;
}
else
{
a[i+1]+=q2;
q+=a[i]+1-a[i+1];
ans+=a[i]+1-a[i+1];
a[i+1]=a[i]+1;
}
}
else
{
q=0;
}
}
for(i=k;i<=n;i++)
{
a[i]+=q;
if(a[i]<a[i+1])
{
break;
}
}
q=0;
for(i=k;i<=n;i++)
{
if(a[i]<=a[i+1])
{
q2=q;
if(a[i]+q>a[i+1])
{
a[i]+=q;
}
else
{
a[i]+=q2;
q+=a[i+1]+1-a[i];
ans+=a[i+1]+1-a[i];
a[i]=a[i+1]+1;
}
}
else
{
q=0;
}
}
if(Final_ans==-1)
{
Final_ans=ans;
}
Final_ans=min(Final_ans,ans);
}
cout<<Final_ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |