윤성우 자료구조에서 배웠던대로 힙에 데이터를 넣고 빼는 과정은 이렇다 이것이 파이썬에서는 heapq 라이브러리로 아주 쉽게 구현이 된다 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import sys import heapq as hq # heap 불러오기 # sys.stdin = open("input", "rt") a=[] # heap을 사용하려면 빈 리스트가 있어야 한다 while True: n=int(input()) if n==-1: break elif n==0: if len(a)==0: print(-1) else: print(hq.heappop(a)) # heapq 에서 heappop은 루트 노드 값을 pop else: hq.heappush(a, n) ..