The greedy idea is: the greedy way of data sorting
is carried out n-1 times, and the two smallest sums of Party A each time enter the queue, and then add each sum
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x;
bool operator<(const node &a)const
{
return x > a.x;//优先队列中和结构体排序不一样
}
} num;
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
priority_queue<node>que;
for(int i=0; i<n; i++)
{
scanf("%d",&num.x);
que.push(num);
}
int sum=0;
for(int i=0; i<n-1; i++)
{
node n1,n2;
n1=que.top();
que.pop();
n2=que.top();
que.pop();
int t=n1.x+n2.x;
sum+=t;
num.x=t;
que.push(num);
}
cout<<sum<<endl;
}
}