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<cstdio>
#define abs(X)(X>0?X:-(X))
#define ll long long
ll n,a[100005],t,p,ans,mn=1e18;
void binSrch(ll x,ll y)
{
if(x==y)return;
ll pivot=(x+y)/2,d=0,q=0;
for(ll i=0;i<n;i++) {
if(i*pivot<a[i])d+=i;
if(i*pivot>a[i])d-=i;
q+=abs(pivot*i-a[i]);
}
if(q<mn)mn=q;
if(d<0)binSrch(x,pivot);
if(d>0)binSrch(pivot+1,y);
}
int main()
{
ll i;
scanf("%d",&n);
scanf("%d",&a[0]);
t=a[0];
a[0]=0;
for(i=1;i<n;i++) {
scanf("%d",&a[i]);
a[i]-=t;
}
binSrch(0,1000000001);
printf("%lld",mn);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |