add: boj/1715.py

This commit is contained in:
Gyubin Han
2024-05-08 00:07:55 +09:00
parent 8a23b84f69
commit 1044eb92db

25
boj/1715.py Normal file
View File

@@ -0,0 +1,25 @@
import sys
from queue import PriorityQueue
input=sys.stdin.readline
n=int(input().rstrip())
pq=PriorityQueue()
for _ in range(n):
pq.put(int(input().rstrip()))
l=[]
while pq.qsize()>1:
a=pq.get()
b=pq.get()
pq.put(a+b)
l.append(a+b)
while len(l)>1:
a=l.pop()
b=l.pop()
l.append(a+b)
if len(l)==0:
print(0)
else:
print(l.pop())