Pagini recente » Cod sursa (job #470555) | Cod sursa (job #948457) | Cod sursa (job #627122) | Cod sursa (job #2586877) | Cod sursa (job #265805)
Cod sursa(job #265805)
var f,e:text; ok:boolean; v,j:array [1..100] of integer;
s,g,p,o,q,w,i,t,a,b,c:integer; r:array [1..100] of real;
aux4,aux2,aux3:integer; x,y,aux1:real;
BEGIN
assign(f,'energii2.in');reset(f);assign(e,'energii.out');rewrite(e);
readln(f,g);readln(f,w); s:=0;c:=10001;q:=0;y:=0;o:=0;OK:=false;
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) and (j[i]<c) then c:=j[i];
for i:=1 to g do
s:=s+v[i];
if s<w then ok:=true;
if s=w then
for i:=1 to g do
c:=c+j[i];
if s>w then
BEGIN
for i:=1 to g do
r[i]:=v[i] / j[i];
for i:=1 to g-1 do
for t:=i+1 to g do
BEGIN
r[t]:=v[t] / j[t];
if (r[i]<r[t]) and (v[i]<w) then
BEGIN
aux1:=r[t];r[t]:=r[i];r[i]:=aux1;
aux2:=v[t];v[t]:=v[i];v[i]:=aux2;
aux3:=j[t];j[t]:=j[i];j[i]:=aux3;
END;
end;
x:=s;
for i:=1 to g do
y:=y+j[i];
x:=x / y;
for i:=1 to g do
begin
if (r[i]>=x) and (w>o) and (w>o+v[i]) then
begin
q:=q+j[i]; o:=o+v[i];
end;
if (w>o) and (w=o+v[i+1]) then
begin
q:=q+j[i+1];
o:=o+v[i+1];
end;
if (w>o) and (w<o+v[i+1]) then
begin
p:=i;
for i:=i to g-1 do
for t:=i+1 to g do
if j[i]>j[t] then
begin
aux4:=j[t];j[t]:=j[i];j[i]:=aux4;
end;
i:=p+1;
o:=o+v[i];
q:=q+j[i];
end;
end;
END;
if (c<q) and (q>0) then write (e,c) else write (e,q);
if ok=true then write (e,-1);
close(f);close(e);
END.