1107:搬水果
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n;
while(cin>>n&&n)
{
priority_queue<int,less<int>> PQ;
for(int i=0;i<n;++i)
{
int temp;
cin>>temp;
PQ.push(temp);
}
int ret=0;
while(PQ.size()>1)
{
int temp=0;
temp+=PQ.top();
PQ.pop();
temp+=PQ.top();
PQ.pop();
PQ.push(temp);
ret+=temp;
}
cout<<ret<<endl;
}
return 0;
}

浙公网安备 33010602011771号