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.
30 lines
454 B
30 lines
454 B
#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;
|
|
}
|