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 <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=-100;i<100;i++){
rs = min(rs, sim(l+i));
}
cout<<rs<<'\n';
return 0;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |