Advertisement
serega1112

Gleb 2

Jan 28th, 2022
1,129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n1 = int(input())
  2. nums1 = sorted(map(int, input().split()))
  3. n2 = int(input())
  4. nums2 = sorted(map(int, input().split()))
  5. n3 = int(input())
  6. nums3 = sorted(map(int, input().split()))
  7. n4 = int(input())
  8. nums4 = sorted(map(int, input().split()))
  9.  
  10.  
  11. p1 = p2 = p3 = p4 = 0
  12. best = (nums1[p1], nums2[p2], nums3[p3], nums4[p4])
  13.  
  14. while True:
  15.     mn = min(nums1[p1], nums2[p2], nums3[p3], nums4[p4])
  16.     mx = max(nums1[p1], nums2[p2], nums3[p3], nums4[p4])
  17.     if mx - mn < max(best) - min(best):
  18.         best = (nums1[p1], nums2[p2], nums3[p3], nums4[p4])
  19.  
  20.     if nums1[p1] == mn:
  21.         p1 += 1
  22.         if p1 == n1:
  23.             break
  24.     elif nums2[p2] == mn:
  25.         p2 += 1
  26.         if p2 == n2:
  27.             break
  28.     elif nums3[p3] == mn:
  29.         p3 += 1
  30.         if p3 == n3:
  31.             break
  32.     elif nums4[p4] == mn:
  33.         p4 += 1
  34.         if p4 == n4:
  35.             break
  36.  
  37. print(best[0], best[1], best[2], best[3])
  38.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement