Pagini recente » Cod sursa (job #2086244) | Cod sursa (job #104885) | Cod sursa (job #490705) | Cod sursa (job #3213655) | Cod sursa (job #1173384)
program p3;
type roca=record
x,y:integer;
end;
var fi,fo:text;
n,g,r,x2,y2,i,j:integer;
a:array[1..5000] of roca;
d:array[0..10010,0..5010] of integer;
function max(a1,b1:integer):integer;
begin
if a1>=b1 then max:=a1
else max:=b1;
end;
Begin
assign(fi,'rucsac.in');reset(fi);
assign(fo,'rucsac.out');rewrite(fo);
readln(fi,n,g);
for i:=1 to n do readln(fi,a[i].x,a[i].y);
for i:=1 to n do
for j:=0 to g do begin
d[i,j]:=d[i-1,j];
if j>=a[i].x then
d[i,j]:=max(d[i,j],d[i-1,j-a[i].x]+a[i].y);
end;
r:=d[n,g];
writeln(fo,r);
close(fi);
close(fo);
end.