Skip to content

Commit 91a3795

Browse files
author
hangyeol
committed
118차 1번 문제풀이
1 parent 62bae88 commit 91a3795

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
import heapq
3+
4+
def main():
5+
input = sys.stdin.readline
6+
7+
T = int(input())
8+
9+
for _ in range(T):
10+
K = int(input())
11+
fileSize = list(map(int, input().split()))[:K]
12+
13+
heapq.heapify(fileSize)
14+
total = 0
15+
16+
while len(fileSize) >= 2:
17+
first = heapq.heappop(fileSize)
18+
second = heapq.heappop(fileSize)
19+
cost = first + second
20+
total += cost
21+
22+
heapq.heappush(fileSize, cost)
23+
24+
print(total)
25+
26+
27+
if __name__ == '__main__':
28+
main()

0 commit comments

Comments
 (0)