'commit'
This commit is contained in:
29
TangDou/LanQiaoBei/LanQiao13STEMA202210/5_2.cpp
Normal file
29
TangDou/LanQiaoBei/LanQiao13STEMA202210/5_2.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
priority_queue<int> q;
|
||||
while (n--) {
|
||||
int x;
|
||||
cin >> x;
|
||||
q.push(-x);
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
while (q.size() > 1) {
|
||||
int a = q.top();
|
||||
q.pop();
|
||||
int b = q.top();
|
||||
q.pop();
|
||||
|
||||
res -= a + b;
|
||||
q.push(a + b);
|
||||
}
|
||||
|
||||
printf("%d\n", res);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user