/LUTA - Luyện tập (OLPCĐ 2011)

<Problem>

http://ntucoder.net/Problem/Details/64
              Uses Crt;
        Var kq,n,c,i:longint; a,b:array[1..100000] of longint;
        Procedure doicho(var a,b:longint); var tg:longint; begin tg:=a; a:=b; b:=tg; end;
        Procedure Sort(l,r:longint);
        var i,j,x:longint;
        begin
          i:=l; j:=r; x:=a[(l+r) div 2];
          repeat
            while (a[i]<x) do inc(i); while (a[j]>x) do dec(j);
            if (i<=j) then begin doicho(a[i],a[j]); doicho(b[i],b[j]); inc(i); dec(j); end;
          until i>j;
          if (l<j) then Sort(l,j); if (i<r) then Sort(i,r);
        end;
        Begin
          readln(n,c);
          for i:=1 to n do begin read(a[i]);read(b[i]); end; sort(1,n);
          kq:=0;
          for i:=1 to n do
          begin
            //write(a[i],' ',b[i]);
            if c>=a[i] then begin c:=c+b[i]; inc(kq); end;
          end;
          writeln(kq);
          readln;
        End.