比赛 |
20110724 |
评测结果 |
C |
题目名称 |
并行 |
最终得分 |
0 |
用户昵称 |
WSJZX |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-24 12:16:10 |
显示代码纯文本
program parelle1;
var
i,j,n,m,t,total,ans,s:longint;
a,b:array[1..10000] of longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
procedure sort1(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=b[(l+r) div 2];
repeat
while b[i]<x do
inc(i);
while x<b[j] do
dec(j);
if not(i>j) then
begin
y:=b[i];
b[i]:=b[j];
b[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort1(l,j);
if i<r then
sort1(i,r);
end;
function work(t:longint):longint;
var
i,j,l:longint;
begin
work:=0;
l:=1;
for i:=1 to n-1 do
if i=t then
begin
work:=work+abs(a[l]-b[i]);
inc(l);
work:=work+abs(a[l]-b[i]);
inc(l);
end
else
begin
work:=work+abs(a[l]-b[i]);
inc(l);
end;
exit(work);
end;
begin
assign(input,'parelle1.in');reset(input);
assign(output,'parelle1.out');rewrite(output);
while not eof do
begin
readln(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n-1 do
read(b[i]);
sort(1,n);
sort1(1,n-1);
ans:=maxlongint;
for i:=1 to n-1 do
begin
m:=work(i);
if m<ans then ans:=m;
end;
writeln(ans);
readln(s);
end;
close(input);close(output);
end.