比赛 |
20110724 |
评测结果 |
MMMMMMMMMM |
题目名称 |
并行 |
最终得分 |
0 |
用户昵称 |
老虎小飞 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-24 11:35:27 |
显示代码纯文本
type
xxxx=array[0..10000] of longint;
var
a,b,v:xxxx;
n,i,j,m:longint;
f:array[0..10000,0..10000]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)+1];
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;
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;
read(n);
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);
for i:=2 to n do begin
f[i,i]:=f[i-1,i-1]+suan(i,i);
f[i,i-1]:=min(f[i-1,i-2]+suan(i,i-1) , f[i-1,i-1]+v[i]);
end;
writeln(f[n,n-1]);
close(input);close(output);
end.