728x90
반응형
골드 5 난이도 치고는 매우 쉬운 우선순위 큐 문제이다.
최대 힙 우선순위 큐로 구현해서 N번째 pop결과를 출력해주는 식으로 풀어도 답은 맞지만 메모리 초과가 뜬다.
heapq의 nlargest를 사용해서 해결했다 -> q값 중 제일 큰 N개의 값을 추출
import heapq
N = int(input())
q = []
for _ in range(N):
for n in map(int, input().split()):
heapq.heappush(q, n)
q = heapq.nlargest(N, q)
heapq.heapify(q)
print(heapq.heappop(q))
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 1238번 파티(python) (0) | 2021.04.10 |
---|---|
백준 알고리즘 1715번 카드 정렬하기(python) (0) | 2021.04.07 |
백준 알고리즘 21335번 Another Eruption(python) (0) | 2021.04.04 |
백준 알고리즘 11367번 Report Card Time(python) (0) | 2021.03.25 |
백준 알고리즘 11319번 Count Me In(python) (0) | 2021.03.25 |