#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
priority_queue<int,vector<int>,greater<int> > q;
int cou[150],lhf=0;
memset(cou,0,sizeof(cou));
while(n--)
{
int t;
scanf("%d",&t);
q.push(t);
}
while(!q.empty())
{
int m=q.top();
q.pop();
if(!q.empty())
{
int n=q.top();
q.pop();
int p=m+n;
lhf+=p;
q.push(p);
}
}
printf("%d",lhf);
}
SDUT2127树-堆结构练习——合并果子之哈夫曼树
最新推荐文章于 2024-04-14 22:49:14 发布