# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
23670 | leejseo | 전봇대 (KOI13_pole) | C++14 | 39 ms | 2292 KiB |
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 <algorithm>
#define abs(a) ((a)>0?(a):-(a))
#define min(a, b) ((a)<(b)?(a):(b))
int N;
int X[100000];
long long D, Ans;
struct bot{
int x, id;
} Bot[100000];
bool cmp(bot a, bot b){
return (long long)a.x * (long long)b.id < (long long)b.x * (long long)a.id;
}
long long cost(long long d){
int i;
long long sum = 0;
for (i=1; i<N; i++){
sum += abs(i*d - X[i]);
}
return sum;
}
int main(void){
int i;
long long sum, t;
scanf("%d", &N);
for (i=0; i<N; i++) scanf("%d", &X[i]);
for (i=1; i<N; i++){
Bot[i].x = X[i];
Bot[i].id = i;
}
std::sort(Bot+1, Bot+N, cmp);
sum = N; sum = sum*(sum-1)/2;
t = 0;
for (i=1; i<N; i++){
if (t+1 <= (sum+1)/2 && (sum+1)/2 <= t+Bot[i].id) break;
t += Bot[i].id;
}
D = Bot[i].x / Bot[i].id;
printf("%lld\n", min(cost(D), cost(D+1)));
return 0;
}
Compilation message (stderr)
# | 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... |