Cod sursa(job #198331)
var g,w,i,j:longint;
e,c: longint;
v:array [1..10000] of longint;
begin
assign(input,'energii.in'); reset(input);
assign(output,'energii.out'); rewrite(output);
readln(g); readln(w);
for i:=1 to g do begin
readln(e,c);
for j:=w downto 1 do
if v[j]<>0 then begin
if v[j+e]=0 then v[j+e]:=c+v[j]
else
if v[j+e]>c+v[j] then v[j+e]:=c+v[j];
end;
if (v[e]=0) or (v[e]>c) then v[e]:=c;
end;
j:=w;
for i:=w to 10000 do
if (v[i]<v[j])and(v[i]>0) then j:=i;
write(v[j]);
close(input); close(output);
end.