-
코드
import heapq import sys left, right = [], [] n = int(input()) for _ in range(n): x = int(sys.stdin.readline()) if len(left) == len(right): heapq.heappush(left, (-x, x)) else: heapq.heappush(right, (x, x)) if right and left[0][1] > right[0][1]: left_value = heapq.heappop(left)[1] right_value = heapq.heappop(right)[1] heapq.heappush(right, (left_value, left_value)) heapq.heappush(left, (-right_value, right_value)) print(left[0][1])
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 11049번 행렬 곱셈 순서 (파이썬) (0) 2022.01.04 [백준] 11066번 파일 합치기 (파이썬) (0) 2022.01.04 [백준] 11286번 절댓값 힙 (파이썬) (0) 2022.01.04 [백준] 1927번 최소 힙 (파이썬) (0) 2022.01.04 [백준] 11279번 최대 힙 (파이썬) (0) 2022.01.04