Skip to content

Commit 375d527

Browse files
Merge pull request #733 from gmlrude/main
[박희경] 118차 라이브 코테 제출
2 parents f71b15a + 4ce8d9c commit 375d527

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
import heapq
3+
4+
input = sys.stdin.readline
5+
6+
t = int(input())
7+
for _ in range(t):
8+
k = int(input())
9+
file_size = list(map(int, input().split()))
10+
heapq.heapify(file_size)
11+
12+
res = 0
13+
while len(file_size) > 1:
14+
cost = heapq.heappop(file_size) + heapq.heappop(file_size)
15+
res += cost
16+
heapq.heappush(file_size, cost)
17+
print(res)
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
import heapq
3+
4+
input = sys.stdin.readline
5+
6+
n = int(input())
7+
cards = []
8+
for _ in range(n):
9+
cards.append(int(input()))
10+
11+
heapq.heapify(cards)
12+
total = 0
13+
while len(cards) > 1:
14+
sum = heapq.heappop(cards) + heapq.heappop(cards)
15+
total += sum
16+
heapq.heappush(cards, sum)
17+
18+
print(total)

0 commit comments

Comments
 (0)