Pagini recente » Cod sursa (job #2278748) | Cod sursa (job #2808645) | Cod sursa (job #2949631) | Cod sursa (job #1441579) | Cod sursa (job #2150925)
Program ProbDisRuc;
type natural = 0..10000;
tab = array[natural] of natural;
obj = record
g,p:natural;
end;
var a:array[natural] of obj;
b:tab;
i,j,n,w:natural;
f,g:text;
begin
assign(f,'rucsac.in');
assign(g,'rucsac.out');
reset(f);
rewrite(g);
readln(f,n,w);
for i:=1 to n do
readln(f,a[i].g,a[i].p);
for i:=1 to n do begin
for j:=w downto a[i].g do
if b[j]<b[j-a[i].g]+a[i].p then begin
b[j]:=b[j-a[i].g]+a[i].p;
end;
end;
writeln(g,b[w]);
close(f);
close(g);
end.