You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
431 B
20 lines
431 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
int n, x, ans;
|
|
priority_queue<int, vector<int>, greater<int> > q;//从大到小
|
|
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++) cin >> x, q.push(x);
|
|
while (q.size() >= 2) {
|
|
int a = q.top();
|
|
q.pop();
|
|
int b = q.top();
|
|
q.pop();
|
|
ans += a + b;
|
|
q.push(a + b);
|
|
}
|
|
cout << ans << endl;
|
|
return 0;
|
|
} |