poj3253

#include <iostream>
#include <queue>

using namespace std;

int main()
{
    priority_queue<int,vector<int>,greater<int> > q;//注意
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int tmp;cin>>tmp;
        q.push(tmp);
    }
    long long ans=0;
    while(!q.empty())
    {
        int a=q.top();q.pop();
        if(q.empty()) break;
        int b=q.top();q.pop();
        int newnum=a+b;
        ans+=newnum;
        q.push(newnum);
    }
    cout<<ans<<endl;
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章