-
Notifications
You must be signed in to change notification settings - Fork 0
/
B_Equal_XOR.py
51 lines (45 loc) · 1.28 KB
/
B_Equal_XOR.py
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
t = int(input()) # number of test cases
for _ in range(t):
n, k = map(int, input().split()) # read n and k
a = list(map(int, input().split())) # read the list of integers
# Your code for processing the test case goes here
first = a[:n]
second = a[n:]
intersection = set(first) & set(second)
ans = []
flag = False
if intersection:
first.sort()
second.sort()
for i in range(2*k):
if intersection:
ans.append(intersection.pop())
# first.remove(ans[-1])
# second.remove(ans[-1])
else:
flag = True
break
if flag:
if len(ans) % 2 != 0:
ans.pop()
ans1 = ans[:]
ans2 = ans[:]
for i in range((2*k)-len(ans)):
ans1.extend([first.pop()])
ans2.extend([second.pop()])
print(*ans1)
print(*ans2)
else:
print(*ans)
print(*ans)
else:
ans1 = []
first.sort()
for i in range(2*k):
ans1.append(first.pop())
print(*ans1)
ans2 = []
second.sort()
for i in range(2*k):
ans2.append(second.pop())
print(*ans2)