提交时间:2024-08-19 20:49:14
运行 ID: 167929
#include <bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,greater<int>>q; int main() { int n,cnt=0; cin>>n; for(int i = 1;i<=n;i++) { int x; cin>>x; q.push(x); } while(q.size()>1) { int zds = q.top();q.pop(); int cds = q.top();q.pop(); int xs=zds+cds; q.push(xs); cnt+=xs; } cout<<cnt<<endl; return 0; }