提交时间:2024-08-19 22:36:24

运行 ID: 168097

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