Advertisement
Void-voiD

Untitled

Feb 20th, 2023
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | Source Code | 0 0
  1. def merge(A, B):
  2.     dif = 10 ** 7
  3.     i = 0
  4.     j = 0
  5.     ans, ans1 = 0, 0
  6.     while i < len(A) and j < len(B):
  7.         if abs(A[i] - B[j]) < dif:
  8.             dif = abs(A[i] - B[j])
  9.             ans = A[i]
  10.             ans1 = B[j]
  11.         if A[i] < B[j]:
  12.             i += 1
  13.         elif A[i] > B[j]:
  14.             j += 1
  15.         else:
  16.             i += 1
  17.             j += 1
  18.     print(ans, ans1)
  19.  
  20.  
  21. n = int(input())
  22. a = list(map(int, input().split()))
  23. m = int(input())
  24. b = list(map(int, input().split()))
  25. merge(a, b)
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement