-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoArraysAndSwaps.java
48 lines (39 loc) · 1.15 KB
/
TwoArraysAndSwaps.java
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
package Divisions.Div3.Round642;
//code by senurah
import java.util.Arrays;
import java.util.Scanner;
public class TwoArraysAndSwaps {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
int k = scanner.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
b[i] = scanner.nextInt();
}
Arrays.sort(a);
Arrays.sort(b);
for (int i = 0; i < k && i < n; i++) {
if (a[i] < b[n - 1 - i]) {
int temp = a[i];
a[i] = b[n - 1 - i];
b[n - 1 - i] = temp;
} else {
break;
}
}
int sum = 0;
for (int num : a) {
sum += num;
}
System.out.println(sum);
}
scanner.close();
}
}