#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;cin>>n;
priority_queue<long long,vector<long long>,greater<long long> > pq;//重点!!优先队列的初始化!!!
for(int i=0;i<n;i++)
{
long long x;cin>>x;
pq.push(x);
}
long long ans=0;
while(pq.size()>=2)
{
long long x=pq.top();pq.pop();
long long y=pq.top();pq.pop();
ans+=x+y;
pq.push(x+y);
}
cout<<ans;
return 0;
}
通过优先队列解决部分贪心问题
最新推荐文章于 2024-09-02 16:35:28 发布