记录编号 15196 评测结果 WAWWWAAAAAWAWAWWAWWW
题目名称 溶液混合 最终得分 45
用户昵称 Gravatar打不死的羊 是否通过 未通过
代码语言 Pascal 运行时间 0.004 s
提交时间 2009-11-10 16:13:56 内存使用 0.12 MiB
显示代码纯文本
program mix;
type
fxz=array[1..100] of real;
var
f1,f2:text;
i,j,n,gt,dt,g,d:longint;
c,v,gc,gv,dc,dv:fxz;
m,ans,ls:real;
      procedure qsort(left,right:longint; var a,b:fxz);
      var
      l,r:longint;
      x,y:real;
       begin
      l:=left; r:=right; x:=a[(l+r) div 2];
      repeat
      while a[l]>x do inc(l);
      while a[r]<x do dec(r);
      if l<=r then
       begin
       y:=a[l];
       a[l]:=a[r];
       a[r]:=y;
       y:=b[l];
       b[l]:=b[r];
       b[r]:=y;
       inc(l); dec(r);
      end;
      until l>r;
      if l<right then qsort(l,right,a,b);
      if r>left then qsort(left,r,a,b);
      end;
begin assign(f1,'mix.in');
      assign(f2,'mix.out');
      reset(f1);rewrite(f2);
      readln(f1,n);
      for i:=1 to n do
      read(f1,c[i]);
      readln(f1);
      for i:=1 to n do
      read(f1,v[i]);
      readln(f1);
      readln(f1,m);
      for i:=1 to n do
      if c[i]=m then ans:=ans+v[i]
                else if c[i]>m then begin inc(g);gc[g]:=c[i];gv[g]:=v[i];end
                               else begin inc(d);dc[d]:=c[i];dv[d]:=v[i];end;
      dt:=1;gt:=1;
      qsort(1,g,gc,gv);
      qsort(1,d,dc,dv);








      while (dt<=d)and(gt<=g) do
      begin
             ls:=(gc[gt]-m)/(m-dc[dt]);
             if gv[gt]*ls<=dv[dt] then begin ans:=ans+gv[gt]*(1+ls);
                                             gv[gt]:=0;
                                             dv[dt]:=dv[dt]-gv[gt]*ls;
                                        end
                                  else begin ans:=ans+dv[dt]*(1+1/ls);
                                             dv[dt]:=0;
                                             gv[gt]:=gv[gt]-dv[dt]/ls;
                                        end;
             while (dt<=d)and(dv[dt]=0) do inc(dt);
             while (gt<=g)and(gv[gt]=0) do inc(gt);
      end;
      writeln(f2,ans:0:5);
      close(f1);close(f2);
end.