-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpairs_given_sum.py
42 lines (34 loc) · 969 Bytes
/
pairs_given_sum.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
class Solution:
def allPairs(self, A, B, N, M, X):
result = []
for i in A:
complement = X - i
if complement in B:
result.append((i, complement))
if len(result) == 0:
return []
else:
result.sort()
return result
# Driver Code
def main():
T = int(input())
while (T > 0):
sz = [int(x) for x in input().strip().split()]
N, M, X = sz[0], sz[1], sz[2]
A = [int(x) for x in input().strip().split()]
B = [int(x) for x in input().strip().split()]
ob = Solution()
answer = ob.allPairs(A, B, N, M, X)
sz = len(answer)
if sz == 0:
print(-1)
else:
for i in range(sz):
if i == sz-1:
print(*answer[i])
else:
print(*answer[i], end=', ')
T -= 1
if __name__ == "__main__":
main()