We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 91a3795 commit 540993dCopy full SHA for 540993d
1 file changed
live11/test118/문제2/백한결.py
@@ -0,0 +1,28 @@
1
+import sys
2
+import heapq
3
+
4
+def main():
5
+ input = sys.stdin.readline
6
7
+ N = int(input())
8
+ cardSize = []
9
10
+ for _ in range(N):
11
+ card = int(input())
12
+ cardSize.append(card)
13
14
+ heapq.heapify(cardSize)
15
+ total = 0
16
17
+ while len(cardSize) >= 2:
18
+ first = heapq.heappop(cardSize)
19
+ second = heapq.heappop(cardSize)
20
+ cost = first + second
21
+ total += cost
22
23
+ heapq.heappush(cardSize, cost)
24
25
+ print(total)
26
27
+if __name__ == '__main__':
28
+ main()
0 commit comments