Pagini recente » Cod sursa (job #899785) | Cod sursa (job #2561613) | Cod sursa (job #1124223) | Cod sursa (job #1359272) | Cod sursa (job #265346)
Cod sursa(job #265346)
var w:real; t,i,g:integer;
f,e:text; ok:boolean; v,j,r:array [1..101] of real;
x,q,cs,s,aux1,aux2,aux3,a,b,c,min:real;
BEGIN
assign(f,'energii2.in');reset(f);assign(e,'energii.out');rewrite(e);
readln(f,g);readln(f,w);c:=10001;min:=-1;ok:=false; s:=0;cs:=0; q:=0;
for i:=1 to g do
begin
readln(f,a,b);v[i]:=a;j[i]:=b;
end;
for i:=1 to g do
if v[i]>=w then ok:=true;
if ok=true then
for i:=1 to g do
BEGIN
a:=v[i];b:=j[i];
if (a>=w) and (b<c) then
begin
c:=b;min:=a;
end;
END;
if ok=true then write(e,c:0:0);
if ok=false then
for i:=1 to g do
s:=s+v[i];
if (ok=false) and (s<w) then write (e,-1);
if (ok=false) and (s>=w) then
BEGIN
for t:=1 to g do
r[t]:=v[t] / j[t];
for i:=1 to g-1 do
for t:=i+1 to g do
BEGIN
if (r[i]>=r[t]) and (j[i]<j[t]) then
begin
aux1:=r[i];r[i]:=r[t];r[t]:=aux1;
aux2:=v[i];v[i]:=v[t];v[t]:=aux2;
aux3:=j[i];j[i]:=j[t];j[t]:=aux3;
end;
END;
for i:=1 to g do
if (i=g) and (w>q) then
begin
q:=v[i];cs:=j[i];
end;
while w>q do
begin
q:=q+v[i-1];
cs:=cs+j[i-1];
end;
if q>=w then write(e,cs:0:0);
END;
close(f);close(e);
end.