https://www.luogu.org/problemnew/show/P1090
优先队列的经典题目 体现了stl的优越性
#include<bits/stdc++.h> using namespace std; int n,x,ans; priority_queue<int,vector<int>,greater<int> >q; int main() { int i; cin>>n; for(i=0;i<n;i++) cin>>x,q.push(x); while(q.size()>=2) { int a=q.top(); q.pop(); int b=q.top(); q.pop(); ans+=a+b; q.push(a+b); } cout<<ans; }