合并果子

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
int n;
cin>>n;
priority_queue<int,vector<int>,greater<int> > heap;
while(n--)
{
int x;
cin>>x;
heap.push(x);
}
int res=0;
while(heap.size()>1)
{
int a=heap.top();heap.pop();
int b=heap.top();heap.pop();
res+=a+b;
heap.push(res);
}
cout<<res<<endl;
return 0;
}

posted @ 2022-03-17 18:27  小白QIU  阅读(40)  评论(1)    收藏  举报