-
Notifications
You must be signed in to change notification settings - Fork 1
/
B - Two Arrays And Swaps
52 lines (41 loc) · 1.07 KB
/
B - Two Arrays And Swaps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.*;
// 5
// 2 1
// 1 2
// // 3 4
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int k =sc.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for(int g= 0;g<n;g++){
a[g] = sc.nextInt();
}
for(int j= 0;j<n;j++){
b[j] = sc.nextInt();
}
Arrays.sort(b);
Arrays.sort(a);
int i =0;
long sum = 0;
while(k>0){
if(a[i]<b[n-i-1]){
a[i]= b[n-i-1];
k--;
}
i++;
if(i==n){
break;
}
}
for(int y :a){
sum+=y;
}
System.out.println(sum);
}
}
}