Pagini recente » Cod sursa (job #551978) | Cod sursa (job #162404) | Cod sursa (job #2733325) | Cod sursa (job #917924) | Cod sursa (job #73511)
Cod sursa(job #73511)
Program Energii;
var G,W : integer;
EG,CG : array[1..1000] of integer;
E,C : array[1..1000] of longint;
rap : array[1..1000] of real;
Cmin : longint;
procedure Citeste;
var Intrare : text;
i : integer;
begin
assign(Intrare,'energii.in');
reset(Intrare);
readln(Intrare,G);
readln(Intrare,W);
for i:=1 to G do readln(Intrare,EG[i],CG[i]);
close(Intrare);
end;
procedure Update(ng,en,cost : integer);
begin
if (en>=W) then
begin
if (E[ng]<W) or ((E[ng]>=W) and (C[ng]<cost)) then
begin
E[ng]:=en;
C[ng]:=cost;
rap[ng]:=cost/en;
end;
end
else
if (E[ng]<W) and (cost/en<rap[ng]) then
begin
E[ng]:=en;
C[ng]:=cost;
rap[ng]:=cost/en;
end;
end;
procedure Calculeaza;
var i,j : integer;
begin
Cmin:=maxlongint;
for i:=1 to G do
begin
E[i]:=1;
C[i]:=maxlongint;
rap[i]:=maxlongint;
end;
for i:=1 to G do
begin
Update(1,EG[i],CG[i]);
for j:=1 to i-1 do Update(j+1,E[j]+EG[i],C[j]+CG[i]);
end;
for i:=1 to G do
if E[i]>=W then
if C[i]<Cmin then Cmin:=C[i];
end;
procedure Scrie;
var Iesire : text;
begin
assign(Iesire,'energii.out');
rewrite(Iesire);
if Cmin<maxlongint then write(Iesire,Cmin)
else write(Iesire,-1);
close(Iesire);
end;
begin
Citeste;
Calculeaza;
Scrie;
end.