Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def merge(A, B):
- dif = 10 ** 7
- i = 0
- j = 0
- ans, ans1 = 0, 0
- while i < len(A) and j < len(B):
- if abs(A[i] - B[j]) < dif:
- dif = abs(A[i] - B[j])
- ans = A[i]
- ans1 = B[j]
- if A[i] < B[j]:
- i += 1
- elif A[i] > B[j]:
- j += 1
- else:
- i += 1
- j += 1
- print(ans, ans1)
- n = int(input())
- a = list(map(int, input().split()))
- m = int(input())
- b = list(map(int, input().split()))
- merge(a, b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement