#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 10;
int n, k;
int a[MAXN];
int b[MAXN];
int sim(int x){
vector<int> v;
for(int i=0;i<n;i++) v.push_back( abs(a[i]-b[i] + x));
sort(v.begin(),v.end());
int sm = 0;
for(int i=0;i<n-k;i++) sm += v[i];
return sm;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> k;
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++) cin >> b[i];
int l = -2e6;
int r = 2e6;
//for(int i=-20;i<20;i++) cout<<i<<": "<<sim(i)<<endl;
while(l<r){
//cout<<l<<" "<<r<<endl;
int m1 = l + (r-l+2)/3;
int m2 = r - (r-l+2)/3;
if(sim(m1) < sim(m2)){
r = m2;
}else{
l = m1;
}
}
int rs = 1e9;
for(int i=-10;i<10;i++){
rs = min(rs, sim(l+i));
}
cout<<rs<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
755 ms |
4092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
770 ms |
3916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
821 ms |
3952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
362 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
834 ms |
3920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
428 ms |
3912 KB |
Output is correct |
2 |
Incorrect |
508 ms |
3868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
888 ms |
3876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
814 ms |
3996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
530 ms |
4000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |