文章
38
粉丝
11
获赞
2
访问
30.9k
#include<bits/stdc++.h>
using namespace std;
int main(){
priority_queue<int,vector<int>,greater<int>> pq;
int n;
cin >> n;
int x;
for(int i = 0;i < n;i++) {
cin >> x;
pq.push(x);
}
int num1,num2;
int sum = 0;
while(pq.size() > 1){
num1 = pq.top();
pq.pop();
num2 = pq.top();
pq.pop();
sum += num1;
sum += num2;
pq.push(num1 + num2);
}
cout << sum << endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发