

Greedy 알고리즘 문제이다.sort는 하지 않는다.while True: if len < 2: break else: A+B = min(result)(최소/최대)힙 문제이다. heapq사용!list로 card를 입력받은 후, heapify로 list를 heap으로 변환pop을 사용하면 묶음 수가 꺼내(요소 삭제)어지므로 list len == 1 이 될 때까지 반복하는 구조를 갖게한다.## boj, 1715 : 카드 정렬하기, python3
import sys
import heapq
N = int(input())
card = [int(sys.stdin.readline()) for _ in range(N)]
heapq.heapify(card)
result = 0
while len(card) is not 1:
s = 0
for i in range(2):
s += heapq.heappop(card)
result += s
heapq.heappush(card, s)
print(result)

https://www.acmicpc.net/problem/1715