[128,655]平凡なリュック
Python Code
import sys
import heapq
n = int(input())
left_heap, right_heap = [], []
for i in range(n):
num = int(sys.stdin.readline())
if len(left_heap) == len(right_heap):
heapq.heappush(left_heap, -num)
else:
heapq.heappush(right_heap, num)
if right_heap and right_heap[0] < -left_heap[0]:
left = heapq.heappop(left_heap)
right = heapq.heappop(right_heap)
heapq.heappush(left_heap, -right)
heapq.heappush(right_heap, -left)
print(-left_heap[0])
Reference
この問題について([128,655]平凡なリュック), 我々は、より多くの情報をここで見つけました https://velog.io/@eunseo130/12865-평범한-배낭テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol