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 <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
pair <int,int> y[100000];
int N, x[100000], Hab;
long long Ans;
void input(void)
{
int i;
scanf("%d",&N);
for(i=0 ; i<N ; i++)
{
scanf("%d",&x[i]);
if(i)
y[i]=make_pair(x[i]/i,i);
}
Hab=N*(N-1)/2;
Hab/=2;
sort(y+1,y+N);
}
void process(void)
{
int i, s=0, v;
long long temp=0;
for(i=1 ; i<N ; i++)
{
s+=y[i].second;
if(Hab<=s)
{
v=i;
break;
}
}
for(i=1 ; i<N ; i++)
{
Ans+=abs((long long)i*y[v].first-x[i]);
temp+=abs((long long)i*(y[v].first+1)-x[i]);
}
if(Ans>temp)
Ans=temp;
}
void output(void)
{
printf("%lld",Ans);
}
int main(void)
{
input();
process();
output();
return 0;
}
# | 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... |