Pagini recente » Cod sursa (job #2597128) | Cod sursa (job #1088027) | Cod sursa (job #1476054) | Cod sursa (job #883435) | Cod sursa (job #119062)
Cod sursa(job #119062)
type gener=record
e,c:longint;
end;
var f1,f2:text;
i,j,g,w,f:longint;
a:array[1..1010] of gener;
pos,pc:array[0..10000] of longint;
begin
assign(f1,'energii.in');
reset(f1);
assign(f2,'energii.out');
rewrite(f2);
read(f1,g,w);
for i:=1 to g do
read(f1,a[i].e,a[i].c);
pos[0]:=1;
for i:=1 to g do
if (a[i].e>=w)and((a[i].c<pc[w])or(pc[w]=0)) then
pc[w]:=a[i].c
else if a[i].e<w then
for j:=w+a[i].e downto a[i].e do
if pos[j-a[i].e]=1 then
begin
f:=j;
if j>w then
f:=w;
pos[f]:=1;
if (pc[j-a[i].e]+a[i].c<pc[f])or(pc[f]=0) then
pc[f]:=pc[j-a[i].e]+a[i].c;
end;
if pc[w]=0 then
writeln(f2,-1)
else writeln(f2,pc[w]);
close(f1);
close(f2);
end.