Pagini recente » Cod sursa (job #1821469) | Cod sursa (job #2564889) | Cod sursa (job #2777358) | Cod sursa (job #120091) | Cod sursa (job #63337)
Cod sursa(job #63337)
var n,l,i,poz,j,LIT:byte;
a,b,c:array[1..100] of real;
act1,act2:array[1..100] of real;
ok:boolean;
s,s1,mp,va,vb,z,vas,vbs,t,vl1,vl2,vt:real;
ramas:real;
f,g:text;
begin
assign(f,'lapte.in'); reset(f);
assign(g,'lapte.out'); rewrite(g);
read(f,n,LIT);
for i:=1 to n do begin
read(f,a[i],b[i]);
a[i]:=1/a[i];
b[i]:=1/b[i];
c[i]:=a[i]/b[i];
vl1:=vl1+a[i];
vl2:=vl2+b[i];
end;
ok:=true;
repeat
ok:=true;
for i:=1 to n-1 do if c[i]<c[i+1] then begin
ok:=false;
z:=a[i];
a[i]:=a[i+1];
a[i+1]:=z;
z:=b[i];
b[i]:=b[i+1];
b[i+1]:=z;
z:=c[i];
c[i]:=c[i+1];
c[i+1]:=z;
end;
until ok=true;
for i:=1 to n do s:=s+c[i];
s1:=0;
mp:=s;
poz:=n;
while abs(s-2*s1)<=mp do begin
mp:=s-2*s1;
s1:=s1+c[poz];
poz:=poz-1;
end;
poz:=poz+1;
for i:=1 to poz do va:=va+a[i];
for i:=poz+1 to n do vb:=vb+b[i];
t:=0;
if va<vb then begin
t:=trunc(lit/vb);
if lit/vb<>trunc(lit/vb) then t:=t+1;
i:=n+1;
while ramas<lit-(t-1)*vb do begin
i:=i-1;
ramas:=ramas+b[i];
end;
if i>poz then for j:=i-1 downto poz+1 do vas:=vas+a[j];
ramas:=lit-va*(t-1);
va:=va+vas;
ramas:=ramas-va;
if ramas/vl1=trunc(ramas/vl1) then t:=t+ramas/vl1 else t:=t+trunc(ramas/vl1)+1;
end
else begin
t:=trunc(lit/va); for l:=1 to poz do act1[l]:=t;
i:=poz+1;
if lit/va<>trunc(lit/va) then t:=t+1;
while ramas<lit-(t-1)*va do begin
i:=i-1;
ramas:=ramas+a[i];
end;
if i>1 then for j:=i-1 downto 1 do vbs:=vbs+b[j]; for l:=poz downto i do act1[l]:=act1[l]+1;
for l:=i-1 downto 1 do act2[l]:=act2[l]+1;
ramas:=lit-vb*(t-1);
vb:=vb+vbs;
ramas:=ramas-vb;
vt:=t;
if ramas/vl2=trunc(ramas/vl2) then t:=t+ramas/vl2 else t:=t+trunc(ramas/vl2)+1;
for l:=poz+1 to n do act2[l]:=t;
for l:=1 to poz do act2[l]:=t-vt;
end;
writeln(g,t:0:0);
for i:=1 to n do writeln(g,(act1[i]*a[i]):0:0,' ',(act2[i]*b[i]):0:0);
close(g);
end.