题解 | #搬水果#

搬水果

https://www.nowcoder.com/practice/e4c775b0f3ee42a4bb72c26d2e1eef8a

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,m;
	while(cin>>n)
	{
		if(!n)	break;
		priority_queue<int,vector<int>,greater<int>> myQueue;
		while(n--){
			cin>>m;
			myQueue.push(m);
		}
		int res=0;
		while(myQueue.size()>1){
			int a=myQueue.top();
			myQueue.pop();
			int b=myQueue.top();
			myQueue.pop();
			res+=a+b;
			myQueue.push(a+b);
		}
		cout<<res<<endl;	
	}
	return 0;	
} 

全部评论

相关推荐

学历算污点吗?
小何和:快毕业了,BOSS上的od闻着味就来了
点赞 评论 收藏
分享
qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务