We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 05b78ee commit 520f5fdCopy full SHA for 520f5fd
1 file changed
14/4.py
@@ -1,14 +1,23 @@
1
import heapq
2
+
3
n = int(input())
4
5
+# 힙(Heap) 자료구조에 초기 카드 묶음을 삽입
6
heap = []
7
for i in range(n):
8
data = int(input())
9
heapq.heappush(heap, data)
10
11
result = 0
12
13
+# 힙(Heap)에 원소가 1개 남을 때까지
14
while len(heap) != 1:
15
+ # 가장 작은 2개의 카드 묶음 꺼내기
16
one = heapq.heappop(heap)
17
two = heapq.heappop(heap)
18
+ # 카드 묶음을 합쳐서 다시 삽입
19
sum_value = one + two
20
result += sum_value
21
heapq.heappush(heap, sum_value)
22
23
print(result)
0 commit comments