💡문제접근
- Python 이분 탐색 라이브러리인
bisect
를 이용해서 문제를 쉽게 해결할 수 있었다.
- 이 때, 민수는 철수가 낼 카드보다 큰 카드가 있다면 그 카드들 중 가장 작은 카드를 내는데 만약 동일한 카드가 존재한다면 인덱스의 값을 하나씩 증가시켜 중복을 피해야 한다.
- Python3로 제출 시 TLE가 발생
💡코드(메모리 : 610560KB, 시간 : 2092ms, PyPy3로 제출)
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
N, M, K = map(int, input().strip().split())
card_number = list(map(int, input().strip().split()))
submit_card = list(map(int, input().strip().split()))
visited = [False] * (len(card_number) + 1)
card_number.sort()
for card in submit_card:
right_idx = bisect_right(card_number, card)
while True:
if not visited[right_idx]:
visited[right_idx] = True
print(card_number[right_idx])
break
else:
right_idx += 1
💡소요시간 : 12m