using namespace std;
int main()
{
int n;
int x;
while(1)
{
scanf("%d",&n);
if(n==0) break;
priority_queue<int, vector<int>, greater<int> >v;
for(int i=0;i<n;i++)
{
cin>>x;
v.push(x);
}
int t;
int sum=0;
while(v.size()>=2)
{
t=v.top();
v.pop();
t+=v.top();
v.pop();
sum+=t;
v.push(t);
}
cout<<sum<<endl;
}
return 0;
}
0 comments :
Post a Comment