Skip to content

Commit 8c38a8c

Browse files
committed
[BOJ] #1715. 카드 정렬하기 / 골드4 / 5분 / 성공
1 parent 4f219f3 commit 8c38a8c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
import heapq
3+
input = sys.stdin.readline
4+
5+
N = int(input())
6+
cards = [int(input()) for _ in range(N)]
7+
answer = 0
8+
heapq.heapify(cards)
9+
10+
while len(cards) > 1:
11+
a = heapq.heappop(cards)
12+
b = heapq.heappop(cards)
13+
answer += a + b
14+
heapq.heappush(cards, a+b)
15+
16+
print(answer)

0 commit comments

Comments
 (0)