1927번

· 백준
코드 import heapq, sys input = sys.stdin.readline tc = int(input()) hq= [] for _ in range(tc): x = int(input()) if x == 0: print(heapq.heappop(hq)[1]) if hq else print(0) else: heapq.heappush(hq, (abs(x),x)) 우선순위 큐에 넣는 자료형이 단일 값이 아닌 선형 자료구조면(ex. 리스트, 튜플 등) 기본적으로 맨 앞 요소부터 우선적으로 살펴보며 정렬한다.
· 백준
코드 import heapq, sys input = sys.stdin.readline tc = int(input()) h = [] for _ in range(tc): k = int(input()) if k == 0 and not h: print(0) elif k == 0 and h: print(heapq.heappop(h)) elif k!=0: heapq.heappush(h,k) heapq 사용법은 좀 독특한 거 같다... sys.stdin.readline을 쓰지 않으면 시간초과가 난다.