diff --git a/boj/1715.py b/boj/1715.py new file mode 100644 index 0000000..517f7fc --- /dev/null +++ b/boj/1715.py @@ -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())