记录编号 199298 评测结果 AAAAA
题目名称 积木分发 最终得分 100
用户昵称 Gravatarグッド大きな萌菌 是否通过 通过
代码语言 Pascal 运行时间 0.115 s
提交时间 2015-10-26 16:19:17 内存使用 0.24 MiB
显示代码纯文本
program toybrick;
type children=record
	have:longint;
	need:longint;
end;
var
	a,b,n,s,k:longint;
	toy:array[1..10001]of children;
	flag:boolean;
procedure qsort(l,r:longint);
var	
	i,j,mid:longint;
	p:children;
begin
	i:=l;
	j:=r;
	mid:=toy[(l+r)div 2].need;
	repeat
		while toy[i].need<mid do
			inc(i);
		while toy[j].need>mid do
			dec(j);
		if i<=j then 
		begin
			p:=toy[i];
			toy[i]:=toy[j];
			toy[j]:=p;
			inc(i);
			dec(j);
		end;
	until i>j;
	if l<j then qsort(l,j);
	if i<r then qsort(i,r);
end;

begin
	assign(input,'toybrick.in');reset(input);
	assign(output,'toybrick.out');rewrite(output);
	readln(n,s);
	while n<>0 do
	begin
		flag:=true;
		for k:=1 to n do
			readln(toy[k].have,toy[k].need);
		qsort(1,n);
		for k:=1 to n do
		begin
			if s-toy[k].need<0 then
			begin
				flag:=false;
			end;
			s:=s+toy[k].have;
		end;
		if flag then
			writeln('YES')
			else writeln('NO');
		readln(n,s);
	end;
	close(input);close(output);
end.