Pagini recente » Monitorul de evaluare | Diferente pentru downloads intre reviziile 263 si 262 | Diferente pentru runda/hello_world_round_1 intre reviziile 6 si 5 | Profil Simon2712 | Cod sursa (job #2151036)
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
b[i]:=0;
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 begin
if b[j]<b[j-we[i]]+p[i] then
b[j]:=b[j-we[i]]+p[i]
else b[j]:=b[j];
end
else b[j]:=b[j];
end;
writeln(g,b[w]);
close(f);
close(g);
end.