Untitled

public
yousefkarem91 Sep 22, 2024 Never 53
Clone
C++ paste1.cpp 29 lines (26 loc) | 564 Bytes
1
#include <bits/stdc++.h>
2
using namespace std;
3
4
int main() {
5
int t;cin>>t;
6
while(t--)
7
{
8
int n,k;cin>>n>>k;
9
int a[n],b[n];
10
for(int i=0;i<n;i++) {
11
cin>>a[i];
12
}
13
for(int i=0;i<n;i++)
14
cin>>b[i];
15
sort(a,a+n);
16
sort(b,b+n,greater<>());
17
for(int i=0;i<k;i++) {
18
if(b[i]>a[i])
19
swap(a[i],b[i]);
20
}
21
int sum=0;
22
for(int i=0;i<n;i++) {
23
sum+=a[i];
24
}
25
cout<<sum<<'\n';
26
}
27
28
29
}