| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 1927 |
| 문제명 | 최소 힙 |
| 레벨 | 실버 1 |
| 분류 |
우선순위 큐 |
| 시간복잡도 | O(nlogn) |
| 인풋사이즈 | n<=100,000 |
| 사용한 언어 | Python |
| 제출기록 | 35124KB / 148ms |
| 최고기록 | 120ms |
| 해결날짜 | 2021/07/12 |
| 태그 | |
"""Solution code for "BOJ 1927. 최소 힙".
- Problem link: https://www.acmicpc.net/problem/1927
- Solution link: http://www.teferi.net/ps/problems/boj/1927
Tags: [Heap]
"""
import heapq
import sys
def main():
N = int(sys.stdin.readline())
heap = []
for _ in range(N):
x = int(sys.stdin.readline())
if x == 0:
print(heapq.heappop(heap) if heap else '0')
else:
heapq.heappush(heap, x)
if __name__ == '__main__':
main()