比赛 |
20101110 |
评测结果 |
AAAAAAAAAA |
题目名称 |
YL杯超级篮球赛 |
最终得分 |
100 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 20:03:24 |
显示代码纯文本
program ballc;
var
ans:extended;
data:array [0..100000,1..2] of extended;
w:array [1..100000] of extended;
p:array [1..100000] of longint;
n,i:longint;
procedure qsort(a,b,no:longint);
var
i,j,s,t:longint;
begin
if a<b then begin
i:=a;j:=b;
s:=p[(a+b) div 2];
repeat
while data[p[i],no]<data[s,no] do inc(i);
while data[p[j],no]>data[s,no] do dec(j);
if i<=j then begin
t:=p[i];
p[i]:=p[j];
p[j]:=t;
inc(i);
dec(j);
end;
until i>j;
qsort (a,j,no);
qsort (i,b,no);
end;
end;
procedure get(no:integer);
var
i:longint;
suma,sumb,a,b,min:extended;
begin
fillchar (p,sizeof(p),0);
for i:=1 to n do p[i]:=i;
qsort (1,n,no);
a:=0;b:=0;suma:=0;sumb:=0;
for i:=2 to n do begin
b:=b+w[p[i]]*(data[p[i],no]-data[p[1],no]);
sumb:=sumb+w[p[i]];
end;
min:=b;
for i:=2 to n do begin
suma:=suma+w[p[i-1]];
a:=a+suma*(data[p[i],no]-data[p[i-1],no]);
b:=b-sumb*(data[p[i],no]-data[p[i-1],no]);
sumb:=sumb-w[p[i]];
if a+b<min then min:=a+b;
end;
ans:=ans+min;
end;
begin
assign (input,'ballc.in');
reset (input);
assign (output,'ballc.out');
rewrite (output);
fillchar (data,sizeof(data),0);
fillchar (w,sizeof(w),0);
readln (n);
for i:=1 to n do read (w[i]);
for i:=1 to n do readln (data[i,1],data[i,2]);
close (input);
ans:=0;
get(1);get(2);
writeln (ans:0:2);
close (output);
end.