#P1334. 瑞瑞的木板

    ID: 331 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>二叉堆福建省历届夏令营排序

瑞瑞的木板

Description

{{He measured the fence and found that he needs nn wooden boards, each with an integer length lil_i. So, he bought one board long enough, whose length equals the sum of the required nn boards, and decided to cut it into the nn boards he needs (Ruirui produces no sawdust when cutting, so ignore any loss of length).

Ruirui uses a special method: cutting a board of length xx into two pieces costs xx units of energy. He has endless energy, but in the spirit of saving energy, he wants to minimize the total energy used. Clearly, there must be (n1)(n-1) cuts in total. The question is: how should he cut each time? Please compute the minimum possible total energy.}}

Input Format

{{The first line contains an integer nn, the number of boards needed.

Lines 22 to n+1n+1 each contain one integer. The integer on line (i+1)(i+1) is lil_i, the length of the ii-th board.}}

Output Format

{{Output a single integer, the minimum total energy required.}}

3
8
5
8

34

Hint

{{Explanation for Sample 1

Cut the board of length 2121 first into lengths 88 and 1313, costing 2121 units of energy. Then cut the board of length 1313 into 55 and 88, costing 1313 units of energy. The total cost is 3434 units, which is minimal.


Constraints

  • For 100%100\% of the testdata, it is guaranteed that 1n2×1041 \le n \le 2 \times 10^4, 1li5×1041 \le l_i \le 5 \times 10^4.}}

Translated by ChatGPT 5