Pagini recente » Cod sursa (job #964414) | Cod sursa (job #2649134) | Cod sursa (job #133933) | Cod sursa (job #2939639) | Cod sursa (job #146884)
Cod sursa(job #146884)
const max=100000000;
var n,w,x,y,m,i,j:longint;
a:array[0..6001] of longint;
f,g:text;
begin
assign(f,'energii.in');
reset(f);
assign(g,'energii.out');
rewrite(g);
readln(f,n,w);
for i:=1 to w do
a[i]:=max;
m:=max;
for i:=1 to n do begin
read(f,x,y);
if (x>=w) then begin
if y<m then m:=y;
end
else begin
for j:=w-x to w do
if a[j]+y<m then m:=a[j]+y;
for j:=w downto x do
if a[j-x]+y<a[j] then a[j]:=a[j-x]+y;
end;
end;
if m<>max then writeln(g,m)
else writeln(g,'-1');
close(f);
close(g);
end.