警钟长鸣------
查看原帖
警钟长鸣------
1471419
trumansonng楼主2025/1/20 13:33
#include<bits/stdc++.h>
using namespace std;
struct fiurt
{
	int height;
	int tili;
};
bool bijiao(fiurt a,fiurt b)
{
	return a.tili<b.tili;
}
int main()
{
	fiurt apple[8];
	int n=0,s=0,a=0,b=0,cnt=0;
	cin>>n>>s>>a>>b;
	for(int i=0;i<n;i++)
	{
		cin>>apple[i].height>>apple[i].tili;
	}
	sort(apple,apple+n,bijiao);
	for(int i=0;(i<n)&&(s+1);i++)
	{
		if((a+b>=apple[i].height)||(a-b>=apple[i].height))
		{
			cnt++;
			s-=apple[i].tili;
		}
		if(s<0)
		{
			cnt--;
			break;
		}
	}
	cout<<cnt;
	return 0;
}

知道错哪里了吗?

最开始我在Dev里写的代码,为了调试,就将结构体和变量都设成了局部变量

因为main给的空间很小所以我就开了8个结构体

调试完我就直接提交了

然后https://www.luogu.com.cn/record/199422673

所以 结构体一定要开大了

这样就可以https://www.luogu.com.cn/record/199423012

2025/1/20 13:33
加载中...