#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> Pi;
int n;
ll ans;
int p[100010];
ll f(int x)
{
int i;
ll ret=0;
for(i=1;i<n;i++){
ret+=abs((ll)p[i]-(ll)i*x);
}
return ret;
}
int main()
{
int i;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",p+i);
int st=0,en=1e9,mi;
while(st<=en){
mi=(st+en)>>1;
ll t=f(mi);
if(t<f(mi+1))ans=t,en=mi-1;
else st=mi+1;
}
printf("%lld\n",ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1476 KB |
Output is correct |
2 |
Correct |
0 ms |
1476 KB |
Output is correct |
3 |
Correct |
0 ms |
1476 KB |
Output is correct |
4 |
Correct |
0 ms |
1476 KB |
Output is correct |
5 |
Correct |
0 ms |
1476 KB |
Output is correct |
6 |
Correct |
0 ms |
1476 KB |
Output is correct |
7 |
Correct |
0 ms |
1476 KB |
Output is correct |
8 |
Correct |
0 ms |
1476 KB |
Output is correct |
9 |
Correct |
0 ms |
1476 KB |
Output is correct |
10 |
Correct |
0 ms |
1476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1476 KB |
Output is correct |
2 |
Correct |
0 ms |
1476 KB |
Output is correct |
3 |
Correct |
0 ms |
1476 KB |
Output is correct |
4 |
Correct |
0 ms |
1476 KB |
Output is correct |
5 |
Correct |
0 ms |
1476 KB |
Output is correct |
6 |
Correct |
0 ms |
1476 KB |
Output is correct |
7 |
Correct |
0 ms |
1476 KB |
Output is correct |
8 |
Correct |
0 ms |
1476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1476 KB |
Output is correct |
2 |
Correct |
0 ms |
1476 KB |
Output is correct |
3 |
Correct |
0 ms |
1476 KB |
Output is correct |
4 |
Correct |
0 ms |
1476 KB |
Output is correct |
5 |
Correct |
0 ms |
1476 KB |
Output is correct |
6 |
Correct |
0 ms |
1476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1476 KB |
Output is correct |
2 |
Correct |
28 ms |
1476 KB |
Output is correct |
3 |
Correct |
20 ms |
1476 KB |
Output is correct |
4 |
Correct |
28 ms |
1476 KB |
Output is correct |
5 |
Correct |
28 ms |
1476 KB |
Output is correct |
6 |
Correct |
28 ms |
1476 KB |
Output is correct |