优先队列简单运用

#include<iostream>
#include<queue>
using namespace std;
int main()
{
    int n,num;
    priority_queue<int,vector<int>,greater<int> > qu;
    while(cin >> n && n){
        for(int i = 0;i < n;++i){
            cin >> num;
            qu.push(num);
        }
        int ans = 0;
        while(1 < qu.size()){
            int a = qu.top();
            qu.pop();
            int b = qu.top();
            qu.pop();
            ans += a + b;
            qu.push(a + b);
        }
        cout << ans << endl;
    }
}