#P1334. 瑞瑞的木板
瑞瑞的木板
Description
{{He measured the fence and found that he needs wooden boards, each with an integer length . So, he bought one board long enough, whose length equals the sum of the required boards, and decided to cut it into the 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 into two pieces costs 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 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 , the number of boards needed.
Lines to each contain one integer. The integer on line is , the length of the -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 first into lengths and , costing units of energy. Then cut the board of length into and , costing units of energy. The total cost is units, which is minimal.
Constraints
- For of the testdata, it is guaranteed that , .}}
Translated by ChatGPT 5
京公网安备 11011102002149号