Pagini recente » Cod sursa (job #2987584) | Autentificare | Cod sursa (job #2254114) | Cod sursa (job #2092176) | Cod sursa (job #629714)
Cod sursa(job #629714)
Program gutui;
type tip=record
h,g:longint;
end;
var a:array [1..100000] of tip;
b1:array [1..1 shl 15] of char;
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');
settextbuf(fi,b1);
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.