提交时间:2024-08-19 21:40:46

运行 ID: 167989

#include<iostream> #include<queue> using namespace std; priority_queue<int,vector<int>,greater<int>> q; int main(){ int n,s=0,x,y; cin>>n; for(int i = 1; i <= n; i++){ cin>>x; q.push(x); } while(q.size() > 1){ x = q.top(); q.pop(); y = q.top(); q.pop(); s += x+y; q.push(x+y); } cout<<s; return 0; }