Pagini recente » Cod sursa (job #631905) | Cod sursa (job #590457) | Borderou de evaluare (job #2777881) | Borderou de evaluare (job #2247802) | Cod sursa (job #614308)
Cod sursa(job #614308)
Program rucsac_arena;
var f1,f2:text;
cost,g:array[0..10000] of integer;
cistig:array[0..10000,0..10000] of longint;
i,j,n:0..5000;
w:0..10000;
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-1];
writeln(f2,cistig[n,w]);
close(f1); close(f2);
end.