Pagini recente » Cod sursa (job #1929058) | Cod sursa (job #418948) | Cod sursa (job #537037) | Cod sursa (job #115053) | Cod sursa (job #2151030)
Program ProbDisRuc;
type natural = word;
tab = array[natural] of natural;
var we,p:tab;
b:array[natural] of natural;
i,j,n,w,s: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,we[i],p[i]);
for i:=1 to n do begin
for j:=w downto 1 do
if we[i]<=j then
if b[j]<b[j-we[i]]+p[i] then begin
b[j]:=b[j-we[i]]+p[i];
end;
end;
writeln(g,b[w]);
close(f);
close(g);
end.