提交时间:2024-08-19 19:39:35

运行 ID: 167854

#include<bits/stdc++.h> using namespace std; priority_queue<int, vector<int>, greater<int> > q; int n, x, ans; int main(){ cin >> n; for(int i = 1;i <= n;i++){ cin >> x; q.push(x); } while(q.size() > 1){ int x = q.top(); q.pop(); int y = q.top(); q.pop(); ans += x + y; q.push(x + y); } cout << ans << endl; return 0; }