提交时间:2023-09-03 13:42:26

运行 ID: 100801

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