#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int N,M, K;
double differ[100000];
long long a[100000];
long long b[100000];
long long eval(long long x) {
int ini=0,fini=N;
if (x < 0) {
ini =K;
} else {
fini = N-K;
}
long long s= 0;
for (int i = ini; i < fini; i++) {
s+=abs(differ[i]+x);
}
return s;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >>N>>K;
for (int i= 0; i < N; i ++) {
cin >> a[i];
}
for (int i= 0; i < N; i ++) {
cin >> b[i];
differ[i]=a[i]-b[i];
}
// return 0;
sort(differ,differ+N);
// return 0;
long long best=eval(0);
for (int i = -2e5; i <=2e5; i++) {
best=min(best,eval(i));
}
cout << best;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
384 KB |
Output is correct |
2 |
Correct |
31 ms |
384 KB |
Output is correct |
3 |
Correct |
28 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
4088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
4088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
4088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
3456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
4096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
4088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1004 ms |
4112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
4152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
4088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |