#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 |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
1536 KB |
Output is correct |
2 |
Correct |
30 ms |
1536 KB |
Output is correct |
3 |
Correct |
27 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1536 KB |
Output is correct |
2 |
Correct |
30 ms |
1536 KB |
Output is correct |
3 |
Correct |
57 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
1536 KB |
Output is correct |
2 |
Correct |
29 ms |
1536 KB |
Output is correct |
3 |
Correct |
28 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1536 KB |
Output is correct |
2 |
Correct |
27 ms |
2960 KB |
Output is correct |
3 |
Incorrect |
28 ms |
2944 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1508 KB |
Output is correct |
2 |
Incorrect |
30 ms |
2936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |