Thứ Tư, 27 tháng 4, 2022

OLYMPIC PASCAL

type baitap=record
   a,b,id:longint;
   end;
var p:array[1..100000] of baitap;
    n:longint;c:int64;

procedure enter;
var i:longint;
begin
    read(n,c);
    for i:=1 to n do
        read(p[i].a,p[i].b);
end;

function ss(x,y:baitap):boolean;
begin
    if x.a<y.a then exit(true)
    else exit(false);
end;

procedure qs(l,r:longint);
var i,j:longint;x,t:baitap;
begin
   x:=p[(l+r) div 2];
   i:=l;j:=r;
   repeat
      while ss(p[i],x)=true do inc(i);
      while ss(x,p[j])=true do dec(j);
      if i<=j then
         begin
         t:=p[i];p[i]:=p[j];p[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;

procedure solve;
var i,d:longint;
begin
    qs(1,n);
    d:=0;
    for i:=1 to n do
        if c>=p[i].a then
        begin
            inc(d);
            c:=c+p[i].b;
        end
        else break;
    writeln(d);
end;

begin
    assign(input,'olympic.inp');reset(input);
    assign(output,'olympic.out');rewrite(output);
    enter;
    solve;
    close(input);close(output);
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.