Fence Repair

Problem Description

有1<=n<=20000个木棒,要把这n个木棒还原为一根并且每次只可以两个相连接,费用就是每次要接的两个木棒的长度和,要求就是把这个棒还原,要求费用最小。

Input

输入包含多组测试数据,每组测试数据第一行是一个正整数n,接下来n行,每行一个数字,代表木棒长度。

Output

对于每组测试数据,输出一行正整数,表示把棒还原的最小费用。

Sample Input

3
8
5
8

Sample Output

34

Author

kg1991
代码如下:
#include
int node[20005];
void swap(int *a,int *b)
{
        int temp;
        temp = *a;
        *a = *b;
        *b = temp;
}
void heap(int i)
{
        int left = i*2,right=i*2+1,mins = i;
        if(left<=node[0]&&node[left]1&&node[i]


你可能感兴趣的:(ACM)