比赛 20101110 评测结果 EEEEEEEEEE
题目名称 YL杯超级篮球赛 最终得分 10
用户昵称 王者自由 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-10 19:04:56
显示代码纯文本
program ballc;
var i,n:longint;
  A:array of array[1..2]of extended;
  W:array of extended;
  K:array of longint;
  ans:extended;
procedure Qsort(p,r:longint;u:integer);
var i,j:longint; x,t:longint;
begin
  i:=p; j:=r; x:=K[(i+j)div 2];
  repeat
    while A[K[i],u]<A[x,u] do i+=1;
    while A[K[j],u]>A[x,u] do j-=1;
    if i<=j then
    begin
      t:=K[i]; K[i]:=K[j]; K[j]:=t;
      i+=1; j-=1;
    end;
  until i>j;
  if p<j then Qsort(p,j,u);
  if i<r then Qsort(i,r,u);
end;
procedure Solve(x:integer);
var i:longint;
  l,r,sl,sr,min:extended;
begin
  for i:=1 to n do K[i]:=i;
  Qsort(1,n,x);
  l:=0; r:=0; sl:=0; sr:=0;
  for i:=2 to n do
  begin
    sr+=W[K[i]];
    r+=(A[K[i],x]-A[K[1],x])*W[K[i]];
  end;
  min:=r;
  for i:=2 to n do
  begin
    sl+=W[K[i-1]];
    l+=sl*(A[K[i],x]-A[K[i-1],x]);
    r-=sr*(A[K[i],x]-A[K[i-1],x]);
    sr-=W[K[i]];
    if l+r<min then min:=l+r;
  end;
  ans+=min;
end;
begin
  assign(input,'ballc.in'); reset(input);
  assign(output,'ballc.out'); rewrite(output);
  readln(n);
  setlength(W,n);
  for i:=1 to n do read(W[i]);
  setlength(A,n);
  for i:=1 to n do readln(A[i,1],A[i,2]);
  ans:=0;
  setlength(K,n);
  Solve(1);
  Solve(2);
  writeln(ans:0:2);
  close(input); close(output);
end.