mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
6d0ead9b6a
5300-5399
46 lines
895 B
C++
46 lines
895 B
C++
#include <iostream>
|
|
#include <cstdio>
|
|
#include<algorithm>
|
|
#include<cstring>
|
|
#include<functional>
|
|
#include<queue>
|
|
typedef long long ll;
|
|
using namespace std;
|
|
int main()
|
|
{
|
|
int T;
|
|
int n,a;
|
|
priority_queue<ll, vector<ll>, greater<ll> >q;
|
|
scanf("%d",&T);
|
|
while(T--)
|
|
{
|
|
scanf("%d",&n);
|
|
while(!q.empty())
|
|
{
|
|
q.pop();
|
|
}
|
|
for(int i=1; i<=n; i++)
|
|
{
|
|
scanf("%d",&a);
|
|
q.push(a);
|
|
}
|
|
ll sum = 0;
|
|
while(!q.empty())
|
|
{
|
|
ll x = q.top();
|
|
q.pop();
|
|
if(q.empty())
|
|
{
|
|
continue;
|
|
}
|
|
ll y = q.top();
|
|
q.pop();
|
|
ll tmp= x + y;
|
|
sum+=tmp;
|
|
q.push(tmp);
|
|
}
|
|
printf("%I64d\n",sum);
|
|
}
|
|
return 0;
|
|
}
|