Cod sursa(job #1676317)
| Utilizator | Data | 5 aprilie 2016 20:25:07 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
var n,g,i,j,max:longint;
w,p,op:array[0..10000] of longint;
begin
assign(input,'rucsac.in');
assign(output,'rucsac.out');
reset(input);
rewrite(output);
read(n,g);
for i:=1 to n do read(w[i],p[i]);
op[0]:=0;
max:=0;
for i:=1 to n do begin
for j:=g downto w[i] do begin
if op[j-w[i]]+p[i]>op[j] then
op[j]:=op[j-w[i]]+p[i];
if op[j]>max then max:=op[g];
end;
end;
// for i:=1 to g do write(op[i],' ');
write(max);
end.