Pagini recente » Cod sursa (job #2841837) | Cod sursa (job #1282488) | Cod sursa (job #2180784) | Cod sursa (job #1982868) | Cod sursa (job #2004052)
var i,j,m,n,x,y:longint;
t:array[0..5001] of longint;
o:array[1..1000] of record e:longint;
c:longint;
end;
begin
assign(input,'energii.in');
reset(input);
readln(n);
readln(m);
for i:=1 to n do
readln(o[i].e,o[i].c);
close(input);
for i:=1 to n do
for j:=m downto 1 do
begin
if j-o[i].e>=0 then if (t[j-o[i].e]>0)
or (j-o[i].e=0) then x:=t[j-o[i].e]+o[i].c
else x:=1999999999;
if (x<t[j]) or((t[j]=0) and (x<>1999999999)) then t[j]:=x
else t[j]:=t[j+1];
end;
assign(output,'energii.out');
rewrite(output);
if t[m]=0 then write(-1) else write(t[m]);
close(output);
end.