Pagini recente » Cod sursa (job #2949636) | Cod sursa (job #766570) | Cod sursa (job #2117953) | Cod sursa (job #2947893) | Cod sursa (job #614950)
Cod sursa(job #614950)
Program rucsac_arena;
type maxim=0..10001;
var f1,f2:text;
cost,g:array[0..5001] of maxim;
cistig:array[0..5001,0..10001] of longint;
w,j:maxim;
n,i : 0..5001;
Function max(a,b:longint):longint;
begin
if a>b then max:=a
else max:=b;
end;
begin
assign(f1,'rucsac.in'); reset(f1); readln(f1,n,w);
for i:=1 to n do read(f1,g[i],cost[i]);
assign(f2,'rucsac.out'); rewrite(f2);
for i:=1 to n do
for j:=1 to w do
if g[i]<=j then cistig[i,j]:=max(cistig[i-1,j],cistig[i-1,j-g[i]] + cost[i])
else cistig[i,j]:=cistig[i-1,j];
writeln(f2,cistig[n,w]);
close(f1); close(f2);
end.