#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct cmp
{
bool operator () (ll a,ll b)
{
return a>b;
}
};
int main()
{
ll N;
while(scanf("%lld",&N)==1&&N)
{
priority_queue<ll,vector<ll>,cmp>q;
ll temp;
for(ll i=1;i<=N;i++)
{
scanf("%lld",&temp);
q.push(temp);
}
ll ans=0;
while(q.size()>=2)
{
ll a=q.top();
q.pop();
ll b=q.top();
q.pop();
ll c=a+b;
ans+=c;
q.push(c);
}
printf("%lld\n",ans);
}
return 0;
}
哈夫曼编码(Add All,uva 10954)
最新推荐文章于 2019-04-29 21:32:30 发布