Skip to content

Instantly share code, notes, and snippets.

@mivvka
Created October 31, 2021 11:30
Show Gist options
  • Save mivvka/64f9e24408312432a8b691c4d9c132ef to your computer and use it in GitHub Desktop.
Save mivvka/64f9e24408312432a8b691c4d9c132ef to your computer and use it in GitHub Desktop.
# P2. Сумма: ближайшая
import numpy as np
n = int(input())
listA = np.array([int(x) for x in input().split()], int)
listB = np.array([int(x) for x in input().split()], int)
listA.sort()
listB.sort()
lenA = len(listA)
lenB = len(listB)
A = listA[0]
B = listB[0]
smm = sum([A, B])
matrixS = np.array([abs((x + y) - n) for x in listA for y in listB]).reshape(lenA, lenB)
indices = np.where(matrixS == matrixS.min())
print(listA[indices[0][0]], listB[indices[1][0]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment