提交时间:2024-08-19 23:23:33
运行 ID: 168171
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; priority_queue<int, vector<int>, greater<int>> minh; for (int i = 0; i < n; ++i) { int v; cin >> v; minh.push(v); } long long sum = 0; while (minh.size() > 1) { int first = minh.top(); minh.pop(); int second = minh.top(); minh.pop(); sum = sum + first + second; minh.push(first + second); } cout << sum << endl; return 0; }