import heapq
import sys
input = sys.stdin.readline
n= int(input())
h = []
ans = 0
for _ in range(n):
x = int(input())
heapq.heappush(h,x)
while len(h) > 1:
a = heapq.heappop(h)
b = heapq.heappop(h)
ans += a+b
heapq.heappush(h,a+b)
print(ans)
# 계속 answer 을 a+b 대신 넣어서 누적값 때문에 틀렸다고 나왔던 문제 ㅋㅋ .. 정신 차리자
'문제풀이 > 백준(Boj) 문제풀이' 카테고리의 다른 글
[백준][BFS] 7562.나이트의 이동 (파이썬/Python) (0) | 2022.01.17 |
---|---|
[백준][Dijkstra/다익스트라] 1504번.특정한 최단 경로 (파이썬/Python) (0) | 2022.01.13 |
[백준][DFS] 1967. 트리의 지름 (파이썬/Python) (0) | 2022.01.10 |
[백준][자료구조/힙] 1655.가운데를 말해요 (파이썬/Python) (0) | 2022.01.10 |
[백준][자료구조/힙] 1655.가운데를 말해요 (파이썬/Python) (0) | 2022.01.08 |