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>
#include<algorithm>
long long i,x[100005],a,m,M,p,q,h;
long long abs(long long z, long long w){return z>w?z-w:w-z;}
long long f(long long t)
{
m=0;
for(i=0;i<a;i++)
{
m+=abs(x[i],i*t);
}
return m;
}
main()
{
scanf("%lld",&a);
for(i=0;i<a;i++)scanf("%lld",&x[i]);
p=0;q=1e9;
while(p!=q-1)
{
h=(p+q)/2;
if(f(h)<f(h+1))q=h;
else p=h;
}
printf("%lld",std::min(f(p),f(q)));
}
# | 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... |