*문제 출처는 백준에 있습니다.
문제 제목: N번째 큰 수 / 2075번 (실버 3단계)
문제 사이트: https://www.acmicpc.net/problem/2075
문제 설명

나의 풀이
import heapq
def main():
n = int(input()) # n번째로 큰 수
heap = []
for _ in range(n):
numbers = list(map(int, input().split()))
for num in numbers:
heapq.heappush(heap, num)
if len(heap) > n:
heapq.heappop(heap)
print(heap[0]) # 최소 힙이므로, n번째로 큰 값이 루트에 있음
if __name__ == "__main__":
main()

※ 알아야 할 것
https://newkimjiwon.tistory.com/179
[자료구조] 힙(Heap)
힙(Heap)은 완전 이진 트리(Complete Binary Tree) 형태를 가지는 자료구조로, 각 노드의 값이 특정한 조건을 만족하도록 정렬된 트리입니다. 힙은 주로 우선순위 큐(Priority Queue)를 구현할 때 사용되며,
newkimjiwon.tistory.com
'Coding Test > 백준-Python' 카테고리의 다른 글
| 백준 / 최대 곱 / 1500번 / Python (0) | 2025.04.14 |
|---|---|
| 백준 / 수열 / 2559번 / Python (0) | 2025.04.13 |
| 백준 / LCS / 9251번 / Python (0) | 2025.04.10 |
| 백준 / 두 용액 / 2470번 / Python (0) | 2025.04.09 |
| 백준 / 최소 스패닝 트리 / 1197번 / Python (0) | 2025.04.08 |