标签:
<span style="font-size:18px;">#include<stdio.h>
#include<queue>
using namespace std;
typedef long long LL;
int main()
{
int N,m;
scanf("%d",&N);
while(N--)
{
LL ans=0;
int a,b;
priority_queue<int,vector<int>,greater<int> > pq;
scanf("%d",&m);
while(m--)
{
int x;
scanf("%d",&x);
pq.push(x);
}
if(m==1)
{
printf("%d\n",pq.top());
pq.pop();
continue;
}
while(!pq.empty())
{
a=pq.top();
pq.pop();
b=pq.top();
pq.pop();
ans+=(LL)a+b;
if(!pq.empty())
pq.push(a+b);
}
printf("%lld\n",ans);
}
return 0;
}
</span>版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qjt19950610/article/details/47165145