比赛 20120309 评测结果 AAAAA
题目名称 积木分发 最终得分 100
用户昵称 Makazeu 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-03-09 19:29:21
显示代码纯文本
#include <cstdio>
#include <cstdlib>
using namespace std;
const int MAXN=10011;
class Toybrick
{
public:
	int now,left;
}Toy[MAXN];
int N,S;

int cmp(const void *a,const void *b)
{
	class Toybrick *c=(class Toybrick *)a;
	class Toybrick *d=(class Toybrick *)b;
	if(c->left!=d->left)
		return c->left-d->left;
	return d->now-c->now;
}

void init()
{
	scanf("%d %d\n",&N,&S);
	while(N!=0 || S!=0)
	{
		for(int i=1;i<=N;i++)
			scanf("%d %d\n",&Toy[i].now,&Toy[i].left);
		qsort(Toy+1,N,sizeof(Toybrick),cmp);
		bool flag=1;
		for(int i=1;i<=N;i++)
		{
			if(S<Toy[i].left)
			{
				flag=0;
				break;
			}
			S+=Toy[i].now;
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
		scanf("%d %d\n",&N,&S);
	}
}

int main()
{
	freopen("toybrick.in","r",stdin);
	freopen("toybrick.out","w",stdout);
	init();
	return 0;
}