#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;
}
poj3253
最新推荐文章于 2022-03-08 09:19:38 发布