#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000005;
const int INF = 0x3f3f3f3f;
#define reg register
#define IOS ios::sync_with_stdio(false)
int n;
int main(){
int n;
scanf("%d",&n);
priority_queue<int,vector<int>,greater<int> > que;
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
que.push(x);
}
int sum=0;
while(que.size()!=1){
int tmp1,tmp2;
tmp1=que.top();
que.pop();
tmp2=que.top();
que.pop();
sum+=tmp1+tmp2;
que.push(tmp1+tmp2);
}
printf("%d",sum);
return 0;
}
08-07
2365
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交