import sys
import heapq
input = sys.stdin.readline
n=int(input())
leftHeap=[]
rightHeap=[]
answer=[]
for i in range(n):
num=int(input())
if len(leftHeap)==len(rightHeap):
heapq.heappush(leftHeap, (-num, num))
else:
heapq.heappush(rightHeap, (num, num))
if rightHeap and leftHeap[0][1] > rightHeap[0][0]:
min=heapq.heappop(rightHeap)[0]
max=heapq.heappop(leftHeap)[1]
heapq.heappush(leftHeap, (-min, min))
heapq.heappush(rightHeap, (max, max))
answer.append(leftHeap[0][1])
for j in answer:
print(j)
'문제풀이 > 백준(Boj) 문제풀이' 카테고리의 다른 글
[백준][DFS] 1967. 트리의 지름 (파이썬/Python) (0) | 2022.01.10 |
---|---|
[백준][자료구조/힙] 1655.가운데를 말해요 (파이썬/Python) (0) | 2022.01.10 |
[백준][자료구조/힙] 11279.최대 힙 (파이썬/Python) (0) | 2022.01.08 |
[백준][자료구조/힙] 1927.최소 힙 (파이썬/Python) (0) | 2022.01.06 |
[백준][DFS/DP] 2583. 영역 구하기 (파이썬/Python) (0) | 2022.01.05 |