#include <stdio.h>
#define N 100000
long long min(long long a, long long b) { return a < b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int main() {
static int aa[N];
int n, k, i;
long long ans, x;
scanf("%d%d", &n, &k), k = n - k;
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++) {
int a;
scanf("%d", &a);
aa[i] -= a;
}
sort(aa, 0, n);
x = 0;
for (i = 0; i < k / 2; i++)
x -= aa[i];
for (i = k - k / 2; i < k; i++)
x += aa[i];
ans = x;
for (i = k; i < n; i++)
ans = min(ans, x += (aa[i] - aa[i - k / 2]) - (aa[i - k + k / 2] - aa[i - k]));
printf("%lld\n", ans);
return 0;
}
Compilation message
simfonija.c: In function 'main':
simfonija.c:37:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%d%d", &n, &k), k = n - k;
| ^~~~~~~~~~~~~~~~~~~~~
simfonija.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
simfonija.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d", &a);
| ^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
244 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2020 KB |
Output is correct |
2 |
Correct |
45 ms |
1996 KB |
Output is correct |
3 |
Correct |
41 ms |
2036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2048 KB |
Output is correct |
2 |
Correct |
35 ms |
1948 KB |
Output is correct |
3 |
Correct |
32 ms |
1988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2044 KB |
Output is correct |
2 |
Correct |
43 ms |
2036 KB |
Output is correct |
3 |
Correct |
32 ms |
2040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1424 KB |
Output is correct |
2 |
Correct |
29 ms |
1960 KB |
Output is correct |
3 |
Correct |
31 ms |
2056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
2012 KB |
Output is correct |
2 |
Correct |
38 ms |
2084 KB |
Output is correct |
3 |
Correct |
38 ms |
2052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2004 KB |
Output is correct |
2 |
Correct |
31 ms |
1996 KB |
Output is correct |
3 |
Correct |
35 ms |
2052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
2052 KB |
Output is correct |
2 |
Correct |
34 ms |
2032 KB |
Output is correct |
3 |
Correct |
50 ms |
2056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2116 KB |
Output is correct |
2 |
Correct |
43 ms |
2052 KB |
Output is correct |
3 |
Correct |
38 ms |
1964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
1968 KB |
Output is correct |
2 |
Correct |
34 ms |
1964 KB |
Output is correct |
3 |
Correct |
44 ms |
2048 KB |
Output is correct |