文章
35
粉丝
134
获赞
55
访问
26.6k
#include <bits/stdc++.h>
using namespace std;
struct node{
int x;
node(int a){
x=a;
}
};
bool operator<(const node &a,const node&b){
return a.x>b.x;
}
int main(){
priority_queue<node> q;
int n,x;
cin>>n;
for(int i=0;i<n;i++){
cin>>x;
q.push(x);
}
int res = 0;
while(q.size()>1){
node num1 = q.top();
q.pop();
node num2 = q.top();
q.pop();
res+=num1.x+num2.x;
q.push(node{num1.x+num2.x});
}
cout<<res;
return 0;
}
登录后发布评论
暂无评论,来抢沙发