简单有批注
2025-03-02 11:00:25
发布于:贵州
9阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10010];
priority_queue<int, vector<int>, greater<int>>q;
//堆顶元素 q.top();
int main(){
cin >> n;
for(int i = 1; i <= n; i ++ ){
cin >> a[i];
q.push(a[i]);
}
int ans = 0;
while(q.size() > 1){
int x = q.top();
q.pop();
int y = q.top();
q.pop();
ans += x + y;
q.push(x + y);
}
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个