nyoj :连接点击打开链接
数据比较大和一个无语的错误老是wa,再就是利用了优先队列,但是注意的是每次队列中都会遗留一个元素,需要每次都把释放出来,不然就等着wa到底把。
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct cmp
{
bool operator()(long long x,long long y)
{
return x>y;
}
};
priority_queue< long long ,vector< long long >,cmp >q;
//priority_queue<int,vector<int>,cmp >q;
int main()
{
int i,times,m,temp;
long long count;
//int count;
scanf("%d",×);
while(times--)
{
count=0;
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&temp);
q.push(temp);
}
while(q.size()>1)
{
temp=q.top();
q.pop();
temp+=q.top();
q.pop();
q.push(temp);
count+=temp;
}
printf("%lld\n",count);
q.pop();
}
return 0;
}