记录编号 199300 评测结果 AAAAA
题目名称 积木分发 最终得分 100
用户昵称 Gravatar这_不错 是否通过 通过
代码语言 Pascal 运行时间 0.117 s
提交时间 2015-10-26 16:20:05 内存使用 0.24 MiB
显示代码纯文本
program fy;
var a,b:array[1..10010]of longint;
n,s,i,sum:longint;
f:boolean;
procedure qs(l,r:integer);
var i,j,m,t:longint;
begin
  i:=l;
  j:=r;
  m:=b[(l+r)div 2];
  repeat
  while b[i]<m do inc(i);
  while b[j]>m do dec(j);
  if i<=j then
    begin
    t:=a[i];
    a[i]:=a[j];
    a[j]:=t;
	t:=b[i];
    b[i]:=b[j];
    b[j]:=t;
    inc(i);
    dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);
end;
begin
assign(input,'toybrick.in');reset(input);
assign(output,'toybrick.out');rewrite(output);
	readln(n,s);
	while n<>0 do
		begin
			f:=true;
			for i:=1 to n do
				readln(a[i],b[i]);
			qs(1,n);sum:=s;
			for i:=1 to n do
				begin
					if sum<b[i] then 
						begin
							writeln('NO');
							f:=false;break;
						end;
					sum:=sum+a[i];
				end;
			if f then writeln('YES');
			readln(n,s);
		end;
		close(input);
		close(output);
end.