由P1090看<堆>
本蒟蒻并没有学过任何图qwq
果然stl是个好东西
并不理解为什么要用优先队列来建堆qwq
还是好好做堆的题吧( ̄ .  ̄)
我太菜了(。_。)
#include<bits/stdc++.h>
using namespace std;
int n,i,x,y,ans=0;
priority_queue<int ,vector<int>,greater<int> > h;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
h.push(x);
}
for(int i=1;i<n;i++)
{
x = h.top();
h.pop();
y = h.top();
h.pop();
ans+=(x+y);
h.push(x+y);
}
cout<<ans;
return 0;
}