알고리즘

<백준> 11279번 파이썬 알고리즘 [최대 힙]

changha. 2021. 11. 2. 22:43
import sys
import heapq

n = int(sys.stdin.readline())
max_arr = []
for i in range(n):
  x = int(sys.stdin.readline())
  if x > 0 and int(x):
    heapq.heappush(max_arr, -x)
  elif x == 0:
    if max_arr:
      print(-heapq.heappop(max_arr))
    else:
      print(0)