Pagini recente » Cod sursa (job #946424) | Cod sursa (job #716909) | Cod sursa (job #1909348) | Diferente pentru implica-te/arhiva-educationala intre reviziile 223 si 131 | Cod sursa (job #119061)
Cod sursa(job #119061)
type gener=record
e,c:longint;
end;
var f1,f2:text;
i,j,g,w: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 downto a[i].e do
if pos[j-a[i].e]=1 then
begin
pos[j]:=1;
if (pc[j-a[i].e]+a[i].c<pc[j])or(pc[j]=0) then
pc[j]:=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.