合并果子加强版 60pts求调
  • 板块题目总版
  • 楼主NEYCzsj
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/4/5 11:31
  • 上次更新2024/4/5 14:46:04
查看原帖
合并果子加强版 60pts求调
1126949
NEYCzsj楼主2024/4/5 11:31
#include<iostream>
#include<string>
#include<set>
using namespace std;
void read(int &x){ 
	int f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
signed main()
{
	long long a,b,j,i,sum=0;
	int n,c;
	multiset<long long> bg;
	read(n);
	for (i=1;i<=n;i++)
	{
			read(c);
			bg.insert(c);
	}
	while(1)
	{
		a=*bg.begin()+(*(++bg.begin()));
		bg.erase(bg.begin());
		bg.erase(bg.begin());
		bg.insert(a);
		sum=sum+a;
		n--;
		if (n==1)
		{
			printf("%lld" , sum);
			break;
		}
	}
	
	
	return 0;
}//谢谢大佬能在百忙之中帮我改代码
2024/4/5 11:31
加载中...