Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- settle = list(map(int, input().split()))
- m = int(input())
- bomb = list(map(int, input().split()))
- for i in range(len(bomb)):
- bomb[i] = (i + 1, bomb[i])
- bomb.sort(key=lambda x: x[1])
- def find_value(x):
- if x < bomb[0][1]:
- return bomb[0][0]
- if x > bomb[-1][1]:
- return bomb[-1][0]
- left = 0
- right = m - 1
- while right - left > 1:
- medium = (right + left) // 2
- if bomb[medium][1] < x:
- left = medium
- else:
- right = medium
- if x - bomb[left][1] < bomb[right][1] - x:
- return bomb[left][0]
- else:
- return bomb[right][0]
- for i in range(n):
- print(find_value(settle[i]), end=' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement