记录编号 |
26455 |
评测结果 |
AAAAAAAAAA |
题目名称 |
并行 |
最终得分 |
100 |
用户昵称 |
老虎小飞 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.151 s |
提交时间 |
2011-07-24 15:43:35 |
内存使用 |
0.31 MiB |
显示代码纯文本
type
xxxx=array[0..10000] of longint;
var
a,b,v:xxxx;
n,i,j,m:longint;
f:array[0..10000,0..1]of longint;
procedure kp(l,r:longint;var a:xxxx);
var
i,j,t,m:longint;
begin
i:=l;j:=r;m:=a[random(r-l)+l];
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i);dec(j);
end;
until i>j;
if i<r then kp(i,r,a);
if l<j then kp(l,j,a);
end;
function min(a,b:longint):longint;
begin
if a>b then min:=b
else min:=a;
end;
function suan(i,j:longint):longint;
begin
suan:=abs(a[i]-b[j]);
end;
begin
assign(input,'parellel.in');reset(input);
assign(output,'parellel.out');rewrite(output);
randomize;
repeat
read(n); if n=0 then break;
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do read(b[i]);
kp(1,n,a);
kp(1,n-1,b);
b[n]:=20000000;
j:=1;
for i:=1 to n do begin
v[i]:=suan(i,j);
m:=suan(i,j+1);
while m<=v[i] do begin
v[i]:=m;inc(j);m:=suan(i,j+1);
end;
end;
f[1,1]:=suan(1,1);
f[1,0]:=f[1,1];
for i:=2 to n do begin
f[i,1]:=f[i-1,1]+suan(i,i);
f[i,0]:=min(f[i-1,0]+suan(i,i-1) , f[i-1,1]+v[i]);
end;
writeln(f[n,0]);
until n=0;
close(input);close(output);
end.