提交时间:2023-08-23 10:02:44
运行 ID: 99549
#include<bits/stdc++.h> using namespace std; priority_queue <int,vector <int>,greater <int> > p; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,sum = 0; cin>>n; for (int i = 1;i <= n;i++){ int a; cin>>a; p.push(a); } if (n == 1){ cout<<p.top(); return 0; } while (p.size() > 1){ int x = p.top(); p.pop(); int y = p.top(); p.pop(); sum += (x + y); p.push(x + y); } cout<<sum; return 0; }