Pagini recente » Cod sursa (job #3246061) | Cod sursa (job #2466282) | Cod sursa (job #2375106) | Cod sursa (job #1787156) | Cod sursa (job #239477)
Cod sursa(job #239477)
program pascal;
var f,h:text; i,j,n,g,min:longint;
y,c,gr:array[0..20000] of longint;
procedure citire;
begin
assign(f,'energii.in'); reset(f);
assign(h,'energii.out'); rewrite(h);
readln(f,n); readln(f,g);
for i:=1 to n do
readln(f,c[i],gr[i]);
close(f);
end;
procedure dinamik;
begin
y[0]:=0;
for i:=1 to 20000 do y[i]:=maxlongint;
for i:=1 to n do
for j:=g downto 0 do
if y[j]<>maxlongint then
if y[j]+gr[i]<y[j+c[i]] then y[j+c[i]]:=y[j]+gr[i];
min:=maxlongint;
for i:=g to 20000 do
if y[i]<min then min:=y[i];
if min=maxlongint then min:=-1;
end;
procedure afisare;
begin
write(h,min);
close(h);
end;
begin
citire;
dinamik;
afisare;
end.