Cod sursa(job #629712)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 3 noiembrie 2011 20:17:16
Problema Gutui Scor 10
Compilator fpc Status done
Runda teme_upb Marime 1.25 kb
Program gutui;
type tip=record
   h,g:longint;
      end;
var a:array [1..100000] of tip;
    n,h,u,i,j,s,max:longint;
    ok,ok1:boolean;
    fi,fo:text;
procedure sort(l,r:longint);
 var k,i,j:longint;
      y:tip;
 begin
  i:=l; j:=r;
   k:=a[(l+r) div 2].h;
 repeat
  while a[i].h>k do inc(I);
   while a[j].h<k do dec(j);
 if i<=j then
              begin
               y:=a[i];
                a[i]:=a[j];
                  a[j]:=y;
                     inc(i); dec(j);
              end;
 until i>=j;
  if l<j then sort(l,j);
   if i<r then sort(i,r);
 end;
procedure control(i:longint);
 var j,s1,max,k,h1:longint;
begin
 ok:=true; j:=i; max:=0;
  while j<n do begin
            inc(j); s1:=a[i].g; h1:=u;
            for k:=j to n do
             if a[k].h+h1<=h then begin s1:=s1+a[k].g; h1:=h1+u; end;
            if s1>max then max:=s1;
            end;
  s:=max;
end;
begin
 assign(fi,'gutui.in');
  assign(fo,'gutui.out');
 reset(fi); rewrite(fo);
 readln(fi,n,h,u);
 for i:=1 to n do readln(fi,a[i].h,a[i].g);
  sort(1,n);  i:=0; ok:=true;
 for i:=1 to n do begin
               s:=0;
                control(i);
               if s>max then max:=s;
               end;
 write(fo,max);
 close(fo);
end.