-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB-Equal XOR.cpp
72 lines (62 loc) · 1.57 KB
/
B-Equal XOR.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<int> b(n);
vector<int> ans1;
vector<int> ans2;
int cnt1 = 0,cnt2=0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for (int i = 1; i < n; i++) {
if (a[i - 1] == a[i]) {
ans1.push_back(a[i - 1]);
ans1.push_back(a[i]);
a[i - 1] = -1;
a[i] = -1;
cnt1 += 2;
}
}
for (int i = 1; i < n; i++) {
if (b[i - 1] == b[i]) {
ans2.push_back(b[i - 1]);
ans2.push_back(b[i]);
b[i - 1] = -1;
b[i] = -1;
cnt2 += 2;
}
}
for (int i = 0; i < n && cnt1 < 2 * k; i++) {
if (a[i] != -1) {
ans1.push_back(a[i]);
cnt1++;
}
}
for (int i = 0; i < n && cnt2 < 2 * k; i++) {
if (b[i] != -1) {
ans2.push_back(b[i]);
cnt2++;
}
}
for (int i = 0; i < 2*k; i++) {
cout << ans1[i] << " ";
}
cout << "\n";
for (int i = 0; i < 2*k; i++) {
cout << ans2[i] << " ";
}
cout << "\n";
}
return 0;
}