提交时间:2024-08-19 22:45:00
运行 ID: 168112
#include<bits/stdc++.h> using namespace std; int main(){ int n, ans = 0; cin>>n; priority_queue<int, vector<int>, greater<int> > q; for(int i = 1; i <= n; i++){ int x; 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; return 0; }