文章
35
粉丝
134
获赞
55
访问
25.3k
#include <bits/stdc++.h>
using namespace std;
int main(){
//迭代求带权路径和
int n,leaf;
while(cin>>n){
priority_queue<int> q;
for(int i=0;i<n;i++) {
cin>>leaf;
q.push(-leaf);//存入相反数
}
int res=0;
while(q.size()>1){
int leaf1 = q.top();
q.pop();
int leaf2 = q.top();
q.pop();
res = res+leaf1+leaf2;
q.push(leaf1+leaf2);
}
cout<<-res<<endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发