文章
20
粉丝
412
获赞
12
访问
163.3k
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n, x;
while(cin >> n) {
priority_queue<int, vector<int>, greater<int>> myPriorityQueue;
while(n--) {
cin >> x;
myPriorityQueue.push(x);
}
int answer = 0;
while(myPriorityQueue.size() > 1) {
int a = myPriorityQueue.top();
myPriorityQueue.pop();
int b = myPriorityQueue.top();
myPriorityQueue.pop();
answer += a + b;
myPriorityQueue.push(a+b);
}
cout << answer << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发