import heapq
import sys
heap = []
num_count = int(sys.stdin.readline())
for _ in range(num_count):
num = int(sys.stdin.readline())
# 힙이 없는데 출력 할 경우
if not heap and num == 0:
print(0)
continue
# 0 이상 이면 값을 추가
if num > 0:
heapq.heappush(heap, -num)
# 힙이 있으면 출력
if heap and num == 0:
print(-heapq.heappop(heap))
'개발 > 알고리즘' 카테고리의 다른 글
백준 1874번 스택 수열 (0) | 2024.01.22 |
---|---|
백준 1021번 회전하는 큐 (0) | 2024.01.16 |
백준 4949번 균형잡힌 세상 (1) | 2024.01.15 |
백준 9012번 괄호 (0) | 2024.01.10 |
백준 1011번 Fly me to the Alpha Centauri (1) | 2024.01.05 |
import heapq
import sys
heap = []
num_count = int(sys.stdin.readline())
for _ in range(num_count):
num = int(sys.stdin.readline())
# 힙이 없는데 출력 할 경우
if not heap and num == 0:
print(0)
continue
# 0 이상 이면 값을 추가
if num > 0:
heapq.heappush(heap, -num)
# 힙이 있으면 출력
if heap and num == 0:
print(-heapq.heappop(heap))
'개발 > 알고리즘' 카테고리의 다른 글
백준 1874번 스택 수열 (0) | 2024.01.22 |
---|---|
백준 1021번 회전하는 큐 (0) | 2024.01.16 |
백준 4949번 균형잡힌 세상 (1) | 2024.01.15 |
백준 9012번 괄호 (0) | 2024.01.10 |
백준 1011번 Fly me to the Alpha Centauri (1) | 2024.01.05 |