• 直接看代码即可。 ```cpp

    include

    include

    include

using namespace std;

const int N = 1e5 + 10;

int main() { ios::sync_with_stdio(false); int n; cin >> n; priority_queue, greater> heap; int res = 0; while (n—) { int x; cin >> x; heap.push(x); } while (heap.size() > 1) {

  1. int a = heap.top();
  2. heap.pop();
  3. int b = heap.top();
  4. heap.pop();
  5. heap.push(a + b);
  6. res += a + b;
  7. }
  8. cout << res << endl;
  9. return 0;

} ```