用优先队列做的,30分求改
查看原帖
用优先队列做的,30分求改
977653
I_am_a_boy楼主2023/8/8 16:09
#include <iostream>
#include <queue> 
using namespace std;
int main()
{
	int t,i,a,r=0;
	cin>>t;
	priority_queue<int ,vector<int>,greater<int>>h;
	for(i=0;i<=t-1;i++)
	{
		cin>>a;
		h.push(a);
	}
	r=0;
	while(h.size()>=2)
	{
		int a=h.top();
		h.pop();
		int b=h.top();
		h.pop();
		int temp=a+b;
		r=r+temp;
		h.push(temp);
	}
	cout<<r<<endl;
}
2023/8/8 16:09
加载中...