记录编号 |
21719 |
评测结果 |
AAAAAAAAAA |
题目名称 |
YL杯超级篮球赛 |
最终得分 |
100 |
用户昵称 |
ybh |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.325 s |
提交时间 |
2010-11-13 11:29:20 |
内存使用 |
0.87 MiB |
显示代码纯文本
{YL杯超级篮球赛
排序
Author: yangbohua
Time: 2010-11-13}
program ballc;
var
x,y,wx,wy:array[0..50000] of longint;
n,i:longint;
l,r,cost,min,ans:int64;
procedure sort1(l,r:longint);
var
i,j,mid,temp:longint;
begin
i:=l;
j:=r;
mid:=x[(l+r) div 2];
repeat
while x[i]<mid do
inc(i);
while mid<x[j] do
dec(j);
if not(i>j) then
begin
temp:=x[i]; x[i]:=x[j]; x[j]:=temp;
temp:=wx[i]; wx[i]:=wx[j]; wx[j]:=temp;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort1(l,j);
if i<r then
sort1(i,r);
end;
procedure sort2(l,r:longint);
var
i,j,mid,temp:longint;
begin
i:=l;
j:=r;
mid:=y[(l+r) div 2];
repeat
while y[i]<mid do
inc(i);
while mid<y[j] do
dec(j);
if not(i>j) then
begin
temp:=y[i]; y[i]:=y[j]; y[j]:=temp;
temp:=wy[i]; wy[i]:=wy[j]; wy[j]:=temp;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort2(l,j);
if i<r then
sort2(i,r);
end;
begin
assign(input,'ballc.in');
reset(input);
assign(output,'ballc.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
read(wx[i]);
wy[i]:=wx[i];
end;
readln;
for i:=1 to n do
readln(x[i],y[i]);
sort1(1,n);
sort2(1,n);
cost:=0;
for i:=2 to n do
begin
cost:=cost+(x[i]-x[1])*wx[i];
r:=r+wx[i];
end;
l:=wx[1];
min:=cost;
for i:=1 to n-1 do
begin
cost:=cost-r*(x[i+1]-x[i])+l*(x[i+1]-x[i]);
l:=l+wx[i+1];
r:=r-wx[i+1];
if cost<min then min:=cost;
end;
ans:=min;
cost:=0;
for i:=2 to n do
begin
cost:=cost+(y[i]-y[1])*wy[i];
r:=r+wy[i];
end;
l:=wy[1];
min:=cost;
for i:=1 to n-1 do
begin
cost:=cost-r*(y[i+1]-y[i])+l*(y[i+1]-y[i]);
l:=l+wy[i+1];
r:=r-wy[i+1];
if cost<min then min:=cost;
end;
ans:=ans+min;
writeln(ans,'.00');
close(input);
close(output);
end.