|
楼主 |
发表于 2023-4-9 09:12:21
|
显示全部楼层
#include<iostream>
#include<queue>
using namespace std;
int n,tmp,one,two,ans;
int main(){
priority_queue<int,vector<int>,greater<int>> q;
cin>>n;
for(int i = 0;i<n;i++){
cin>>tmp;
q.push(tmp);
}
while(q.size() > 1){
one = q.top();
q.pop();
two = q.top();
q.pop();
ans += one + two;
q.push(ans);
}
cout<<ans;
return 0;
} |
|