【例59.1】 合并果子
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
In an orchard, Duoduo has picked all the fruits and sorted them into different piles based on their types. Duoduo decides to combine all the fruits into one pile.
Each time, Duoduo can merge two piles of fruits, and the energy consumed is equal to the sum of the weights of the two piles. It can be seen that after merges, only one pile remains. The total energy Duoduo consumes during the merging process is equal to the sum of the energy consumed in each merge.
Since Duoduo still needs to exert great effort to carry these fruits home, he wants to save as much energy as possible during the merging process. Assuming each fruit weighs , and given the number of fruit types and the quantity of each type, your task is to design a merging order that minimizes the energy Duoduo consumes and output this minimum energy value.
For example, if there are types of fruits with quantities of , , and , you can first merge the piles of and , resulting in a new pile of , consuming units of energy. Then, merge this new pile with the original third pile, resulting in a new pile of , consuming units of energy. Therefore, Duoduo's total energy consumption is . It can be proven that is the minimum energy consumption.
Input Format
Two lines: the first line contains an integer (), representing the number of fruit types. The second line contains integers separated by spaces, where the -th integer () represents the quantity of the -th type of fruit.
Output Format
A single line containing an integer, representing the minimum energy consumption. The input data guarantees this value is less than .
Sample
3
1 2 915
20251018D班作业(3)
- Status
- Done
- Problem
- 3
- Open Since
- 2025-10-23 0:00
- Deadline
- 2025-10-30 23:59
- Extension
- 24 hour(s)