比赛 20091110 评测结果 WWWWWAAAAAWWWAWWWWWW
题目名称 溶液混合 最终得分 30
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-10 11:45:10
显示代码纯文本
program mix;
var
a,b:array[1..50] of longint;
g,d:array[1..50,1..2] of longint;
i,j,k,m,n,aim,gg,dd,tempg,tempd,yl:longint;
ans,temp:real;
begin
assign(input,'mix.in');reset(input);
assign(output,'mix.out');rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do read(b[i]);
readln(aim);
for i:=1 to n do
begin
if a[i]=aim then ans:=ans+b[i];
if a[i]>aim then begin inc(gg);g[gg,1]:=a[i];g[gg,2]:=b[i]; end;
if a[i]<aim then begin inc(dd);d[dd,1]:=a[i];d[dd,2]:=b[i]; end;
end;
k:=1;
while (gg<>0)and(dd<>0) do
 begin
 tempg:=gg;tempd:=dd;
 gg:=0;dd:=0;
 for i:=1 to tempg do if g[i,2]<>0 then inc(gg);
 for i:=1 to tempd do if d[i,2]<>0 then inc(dd);
 temp:=(g[k,1]-aim)/(aim-d[k,1]);
 if temp*d[k,2]>g[k,2] then yl:=g[k,2] else yl:=d[k,2];
    ans:=ans+yl*2;
    g[k,2]:=g[k,2]-yl;d[k,2]:=d[k,2]-yl;
 end;
writeln(ans:0:5);
close(output);
end.