Pagini recente » Cod sursa (job #2634228) | Cod sursa (job #2649920) | Cod sursa (job #2187536) | Cod sursa (job #3150164) | Cod sursa (job #147563)
Cod sursa(job #147563)
const max=100000000;
var n,w,x,y,m,i,j,f,g:longint;
a:array[0..6001] of longint;
begin
assign(input,'energii.in');reset(input);
assign(output,'energii.out');rewrite(output);
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(input);
close(output);
end.