We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4f219f3 commit 8c38a8cCopy full SHA for 8c38a8c
minjeong/Heap/2025-06-06-[백준]-#1715-카드정렬하기.py
@@ -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