赞
踩
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main(){
int n,x;
priority_queue<int,vector<int>,greater<int> >q;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++){
scanf("%d",&x);
q.push(x);
}
int ans=0;
while(q.size()>1){
int x1=q.top();
q.pop();
int x2=q.top();
q.pop();
ans+=(x1+x2);
q.push(x1+x2);
}
printf("%d\n",ans);
}
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。