比赛 |
20110724 |
评测结果 |
AAAAATAATT |
题目名称 |
并行 |
最终得分 |
70 |
用户昵称 |
ZhouHang |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-24 10:03:16 |
显示代码纯文本
Program parellel;
Const
inf = 'parellel.in';
ouf = 'parellel.out';
Var
n : longint;
p,r,s : array [0..10100] of longint;
min : longint;
Procedure Qsort1(l,r : longint);
Var
i,j,mid,tmp : longint;
Begin
i := l; j := r; mid := p[(l+r) div 2];
repeat
while p[i]<mid do inc(i);
while p[j]>mid do dec(j);
if i<=j then begin
tmp := p[i]; p[i] := p[j]; p[j] := tmp;
inc(i); dec(j);
end;
until j<i;
if l<j then Qsort1(l,j);
if i<r then Qsort1(i,r);
End;
Procedure Qsort2(ll,rr : longint);
Var
i,j,mid,tmp : longint;
Begin
i := ll; j := rr; mid := r[(ll+rr) div 2];
repeat
while r[i]<mid do inc(i);
while r[j]>mid do dec(j);
if i<=j then begin
tmp := r[i]; r[i] := r[j]; r[j] := tmp;
inc(i); dec(j);
end;
until j<i;
if ll<j then Qsort2(ll,j);
if i<rr then Qsort2(i,rr);
End;
Procedure Work;
Var
now,num,i,ans : longint;
flag : boolean;
Begin
min := maxlongint;
for i := 1 to n do
begin
now := 0; num := 0; ans := 0;
while num<n do
begin
inc(now); inc(num);
ans := ans + abs(p[num]-r[now]);
if now=i then begin
inc(num);
ans := ans + abs(p[num]-r[now]);
end;
end;
if ans<min then min := ans;
end;
End;
Procedure Init;
Var
flag : boolean;
i : longint;
Begin
flag := false;
repeat
readln(n);
if n=0 then exit;
for i := 1 to n do
read(p[i]);
readln;
for i := 1 to n-1 do
read(r[i]);
Qsort1(1,n);
Qsort2(1,n-1);
Work;
writeln(min);
until flag;
End;
Begin
Assign(input,inf); Reset(input);
Assign(output,ouf); Rewrite(output);
Init;
Close(input); Close(output);
End.