Logo
(追記) (追記ここまで)

30424번 - Merge the Books 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 1024 MB521100.000%

문제

Little C has $n$ books, each with a weight, and he decides to merge them into a pile.

Each time when Little C merges, he can put one pile of books on top of another to merge them into one pile. If Little C puts the $i$-th pile of books on top of the $j$-th pile of books, the energy Little C needs to consume is the weight of the $i$-th pile of books plus the wear value of the two piles of books.

Initially, each book is in its own pile and the wear values are all 0ドル$. Whenever Little C merges two piles of books, the wear value of the new pile of books formed is twice the larger of the wear values of the two piles of books before merging, plus one. The weight of the new pile of books is the sum of the weights of the two piles of books before merging.

Your task is to design a merging order to minimize the total energy consumption of Little C and output the minimum total energy consumption.

입력

This problem has multiple test data sets.

The first line of the input contains an integers $t,ドル which represents the number of test data sets.

Then, each set of test data is given as input in order. For each set of test data:

The first line of input contains a positive intege $n,ドル which represents the number of books.

The second line of input contains $n$ positive integers $w_1,w_2,\dots,w_n,ドル where $w_i$ represents the weight of the $i$-th book.

출력

For each set of test data, output a line containing an integer, representing the minimum total energy consumption.

제한

For all test data, it is guaranteed that: 1ドル \leq t\leq 10,1\leq n\leq 100,1\leq w_i\leq 10^9$.

예제 입력 1

1
4
1 1 1 1

예제 출력 1

6

If Little C combines the four books in pairs and then combines the two pairs into one, the energy consumption of the first two merging operations is 1ドル$ each, and in the third time, a pile of books with weight of 2ドル$ is placed on top of the other pile. The wear value of the two piles of books is 1ドル$ each, and the energy consumption is 2ドル + 1 + 1 = 4$. Therefore, if Little C chooses this plan, the total energy consumption is only 1ドル + 1 + 4 = 6$. It can be proved that in the above sample, 6ドル$ is the minimum total energy consumption.

힌트

추가 예제

samples.zip ​​​​​​​

출처

Olympiad > National Olympiad in Informatics (China) > NOI 2023 6번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /