#include<bits/stdc++.h>
using namespace std;
int bb[1000];
priority_queue<int,vector<int>,greater<int> > q;
int main()
{
int n,i,lc,m;
scanf("%d",&n);
memset(bb,0,sizeof(bb));
for(i=0; i<n; i++)
{
scanf("%d",&m);
q.push(m);
}
lc=0;
while(!q.empty())
{
int num=q.top();
q.pop();
if(!q.empty())
{
int m=q.top();
q.pop();
int t=num+m;
q.push(t);
lc+=t;
}
}
printf("%d\n",lc);
return 0;
}
树-堆结构练习——合并果子之哈夫曼树
最新推荐文章于 2021-01-31 11:50:53 发布