用队列queue解题
2025-08-25 13:02:08
发布于:浙江
3阅读
0回复
0点赞
根据队列queue,可得:
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int main(){
cin >> n;
priority_queue<int, vector<int>, greater<int>> q;
while (cin >> n) q.push(n);
while (q.size() > 1){
int a = q.top(); q.pop();
int b = q.top(); q.pop();
ans += a + b;
q.push(a + b);
}
cout << ans;
return 0;
}
这里空空如也
有帮助,赞一个