Pagini recente » Cod sursa (job #2961282) | Cod sursa (job #1602803) | Cod sursa (job #3270488) | Cod sursa (job #686009) | Cod sursa (job #197212)
Cod sursa(job #197212)
type gen = record
e,c : longint;
end;
var v : array[1..2001] of gen;
cost,ex : array[0..16001] of longint;
n,w,i,j,cmin,ok : longint;
f,g : text;
begin
assign(f,'energii.in');reset(f);
assign(g,'energii.out');rewrite(g);
read(f,n,w);
for i:=1 to n do
read(f,v[i].e,v[i].c);
cmin:=maxlongint;
ex[0]:=1; cost[0]:=0; ok:=0;
if w<=0 then
begin
cmin:=0; ok:=1;
end;
for i:=1 to n do
for j:=w-1 downto 0 do
if ex[j]=1 then
begin
if ex[j+v[i].e]=0 then
begin
cost[j+v[i].e]:=cost[j]+v[i].c;
ex[j+v[i].e]:=1;
if j+v[i].e>=w then
if cost[j+v[i].e]<cmin then
begin
cmin:=cost[j+v[i].e];
ok:=1;
end
end
else
if cost[j+v[i].e]>cost[j]+v[i].c then
begin
cost[j+v[i].e]:=cost[j]+v[i].c;
if j+v[i].e>=w then
if cost[j+v[i].e]<cmin then
begin
cmin:=cost[j+v[i].e];
ok:=1;
end;
end;
end;
if ok=0 then writeln(g,'-1')
else writeln(g,cmin);
close(g);
end.