提交时间:2024-03-02 15:39:44
运行 ID: 134343
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ ios::sync_with_stdio(0); cin.tie(0); priority_queue<int,vector<int>, greater<int>>q; int n; cin >> n; for(int i = 1;i <= n;i++){ int x; cin >> x; q.push(x); } int ans = 0; for(int i = 1;i < n;i++){ int a = q.top(); q.pop(); int b = q.top(); q.pop(); ans+=a+b; q.push(a+b); } cout << ans; return 0; }