https://www.acmicpc.net/problem/13975
import heapq
t = int(input()) # 테스트 케이스 수
for _ in range(t):
k = int(input()) # 배열의 길이
arr = list(map(int, input().split()))
heapq.heapify(arr)
total = 0
while len(arr) > 1:
a1 = heapq.heappop(arr)
a2 = heapq.heappop(arr)
total += (a1 + a2)
heapq.heappush(arr, (a1 + a2))
print(total)
'알고리즘 문제풀이' 카테고리의 다른 글
풍선 맞추기 [백준 11509] (0) | 2025.03.13 |
---|---|
연료 채우기 [백준 1826] (0) | 2025.03.11 |
멀티탭 스케줄링 [백준 1700] (0) | 2025.03.08 |
흙길 보수하기 [백준 1911] (0) | 2025.03.08 |
다이어트 [백준 1484] (0) | 2025.02.25 |