[이·코·테] Q26. 카드 정렬하기

이정진·2021년 8월 10일
0

이·코·테

목록 보기
20/20
post-thumbnail

소스 코드 :

import heapq

n = int(input())

heap = []
for _ in range(n):
    heapq.heappush(heap, int(input()))

result = 0

while len(heap) != 1:
    one = heapq.heappop(heap)
    two = heapq.heappop(heap)
    total = one + two
    result += total
    heapq.heappush(heap, total)

print(result)

0개의 댓글

관련 채용 정보