close
#include <cstdio>
#include <queue>
using namespace std;
int main()
{
    long long int N, x;
    while (scanf("%d", &N) && N)
    {
        priority_queue<int, vector<int>, greater<int>> PQ;
        for (int i = 0; i < N; ++i)
        {
            scanf("%d", &x);
            PQ.push(x);
        }
        long long int cost = 0;
        while (PQ.size() != 1)
        {
            x = PQ.top();
            PQ.pop();
            x += PQ.top();
            PQ.pop();
            cost += x;
            PQ.push(x);
        }
        printf("%lld\n", cost);
    }
    return 0;
}
#priority-queue
arrow
arrow
    文章標籤
    priority-queue
    全站熱搜
    創作者介紹
    創作者 Nate_Tang 的頭像
    Nate_Tang

    Nate - life is tough,but I'm tougher

    Nate_Tang 發表在 痞客邦 留言(0) 人氣()