#include<bits/stdc++.h>
using namespace std;
#define SIZE 1000000
long long ar[1000010]={0},i,j,status[1000010]={0},k=1;
main()
{
long long n;
while(cin>>n)
{
if(n==0)
break;
long long i,a,b,sum=0,sum1=0;
priority_queue<long long >pq;
for(i=0;i<n;i++)
{
cin>>a;
pq.push(-a);
}
while(pq.size()>1)
{
a=pq.top();
pq.pop();
b=pq.top();
pq.pop();
sum=a+b;
sum1+=sum;
pq.push(sum);
}
cout<<-1*sum1<<endl;
}
}
using namespace std;
#define SIZE 1000000
long long ar[1000010]={0},i,j,status[1000010]={0},k=1;
main()
{
long long n;
while(cin>>n)
{
if(n==0)
break;
long long i,a,b,sum=0,sum1=0;
priority_queue<long long >pq;
for(i=0;i<n;i++)
{
cin>>a;
pq.push(-a);
}
while(pq.size()>1)
{
a=pq.top();
pq.pop();
b=pq.top();
pq.pop();
sum=a+b;
sum1+=sum;
pq.push(sum);
}
cout<<-1*sum1<<endl;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন