80分求助
查看原帖
80分求助
318876
金城武楼主2020/7/1 08:21
#include <bits/stdc++.h>
using namespace std;
int sum;
struct apple
{
	int x;
	int y;
}ap[5005];
bool cmp(apple p,apple q)
{
	return p.y<q.y;
}
int main ()
{
	int n,s;
	int a,b;
	cin>>n>>s;
	cin>>a>>b;
	int len=a+b; 
	for (int i=1;i<=n;i++)
	{
		cin>>ap[i].x>>ap[i].y;
	}
	sort(ap+1,ap+n+1,cmp);
	for (int i=1;i<=n;i++)
	{
		if (len>=ap[i].x)
		{
			if (ap[i].y<s)
			{
				sum++;
				s-=ap[i].y;
			}
		}
		if (s<=0)
		break;
	}
	cout<<sum;
 } 
2020/7/1 08:21
加载中...