Files
PS/boj/1715.py
2024-05-08 00:07:55 +09:00

26 lines
371 B
Python

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())