Cod sursa(job #1615844)
Utilizator | Data | 26 februarie 2016 21:43:59 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.77 kb |
program rucsac;
var f,g:text;
greutate,cost:array[1..5000] of longint;
b:array[1..5000] of int64;
n,gr,i,j:longint;
max:int64;
begin
assign(f,'rucsac.in');
assign(g,'rucsac.out');
reset(f);
rewrite(g);
readln(f,n,gr);
for i:=1 to n do
begin
readln(f,greutate[i],cost[i]);
end;
for i:=1 to n do
for j:=gr downto 1 do
if b[j+greutate[i]]<b[j]+cost[i] then
begin
b[j+greutate[i]]:=b[j]+cost[i];
if b[j+greutate[i]]>max then
max:=b[j+greutate[i]];
end;
writeln(g,max);
close(f);
close(g);
end.