优先队列(类似于合并石子)
#include<iostream>
#include<queue>
using namespace std;
using namespace std;
int n;
priority_queue<int, vector<int>, greater<int>> q;
int main()
{
cin >> n;
for ( int i = 1; i <= n; i ++ )
{
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);
}
cout << res << endl;
return 0;
}