记录编号 |
26533 |
评测结果 |
AAAAATAATT |
题目名称 |
并行 |
最终得分 |
70 |
用户昵称 |
echo |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
3.585 s |
提交时间 |
2011-07-24 21:04:39 |
内存使用 |
0.88 MiB |
显示代码纯文本
program parellel;
var
n,i,j,k,l,t,min:longint;
a,b:array[0..100000] of longint;
max,ans:int64;
procedure sorta(l,r:longint);
var
i,j,mid:longint;
begin
i:=l;j:=r;mid:=a[random(j-i)+i];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if not(i>j) then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);dec(j);
end;
until i>j;
if l<j then sorta(l,j);
if i<r then sorta(i,r);
end;
procedure sortb(l,r:longint);
var
i,j,mid:longint;
begin
i:=l;j:=r;mid:=b[random(j-i)+i];
repeat
while b[i]<mid do inc(i);
while b[j]>mid do dec(j);
if not(i>j) then
begin
t:=b[i];
b[i]:=b[j];
b[j]:=t;
inc(i);dec(j);
end;
until i>j;
if l<j then sortb(l,j);
if i<r then sortb(i,r);
end;
function mat(x1,y1,x2,y2:longint):int64;
var
i,j:longint;
num:int64;
begin
i:=x1;
j:=x2;
num:=0;
if (x1>y1)or(x2>y2) then
begin
exit(0);
end;
while (i<=y1)and(j<=y2) do
begin
num:=num+abs(a[i]-b[j]);
i:=i+1;
j:=j+1;
end;
exit(num);
end;
begin
assign(input,'parellel.in');
assign(output,'parellel.out');
reset(input);
rewrite(output);
readln(n);
while n<>0 do
begin
max:=maxlongint;
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do read(b[i]);
sorta(1,n);
sortb(1,n-1);
for k:=1 to n do
begin
ans:=0;
min:=maxlongint;
ans:=mat(1,k-1,1,k-1)+mat(k+1,n,k,n-1);
for l:=1 to n-1 do
if abs(b[l]-a[k])<min then min:=abs(b[l]-a[k]);
ans:=ans+min;
if max>ans then max:=ans;
end;
writeln(max);
readln(n);
end;
close(input);
close(output);
end.