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 endl "\n"
typedef long long int ll;
vector<int>a,b,c;
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
int n; cin>>n; int k; cin>>k;
c.resize(n+1);
a.resize(n+1);
b.resize(n+1);
for(int i=1; i<=n; i++) {
cin>>a[i];
}
for(int i=1; i<=n; i++) {
cin>>b[i];
c[i]=a[i]-b[i];
}
sort(c.begin()+1,c.end());
int m=c[n/2+(n%2)];
ll sum=0;
for(int i=1; i<=n; i++) {
sum+=abs(c[i]-m);
c[i]=abs(c[i]-m);
}
sort(c.begin(),c.end());
for(int i=1; i<=k; i++) {
if(!c.size()) break;
sum-=c.back();
c.pop_back();
}
cout<<sum<<endl;
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... |