#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
// scanf("%d",&n);
while(scanf("%d",&n)==1&& n){
priority_queue<int,vector<int>,greater<int>>q;
for(int i=0;i<n;i++){scanf("%d",&x); q.push(x);}2
int res=0;
for(int i=0;i<n-1;i++){
int a=q.top(); q.pop();
int b=q.top(); q.pop();
res+=a+b;
q.push(a+b);
}
printf("%d\n",res);
}
return 0;
}
uva 10954 add all
最新推荐文章于 2020-04-24 16:25:04 发布