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;
v.reserve(n);
for(int i=0;i<n;i++) v.push_back( abs(a[i]-b[i] + x));
nth_element(v.begin(),v.begin() + n - k,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];
vector<int> dx;
for(int i=0;i<n;i++) dx.push_back(b[i] - a[i]);
sort(dx.begin(),dx.end());
dx.erase(unique(dx.begin(),dx.end()),dx.end());
int rs = 1e9;
for(auto el : dx){
//cout<<el<<": "<<sim(el)<<'\n';
rs = min(rs,sim(el));
}
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... |