这是一个优先队列的题啊...
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20010;
int n, b = 0, c = 0, a[MAXN];
int main() {
priority_queue<int> q;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
q.push(-a[i]);
}
while (!q.empty()) {
if (q.size() == 1) {
break;
}
b = abs(q.top());
q.pop();
b += abs(q.top());
q.pop();
c += b;
q.push(-b);
}
cout << c;
return 0;
}