Pagini recente » Cod sursa (job #1526639) | Cod sursa (job #551004) | Cod sursa (job #1318703) | Cod sursa (job #2374095) | Cod sursa (job #268015)
Cod sursa(job #268015)
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 min=maxlongint then min:=-1;
end;
procedure afisare;
begin
write(h,min);
close(h);
end;
begin
citire;
dinamik;
afisare;
end.