记录编号 26452 评测结果 EEEEEEEEEE
题目名称 并行 最终得分 0
用户昵称 GravatarWSJZX 是否通过 未通过
代码语言 Pascal 运行时间 0.000 s
提交时间 2011-07-24 15:38:25 内存使用 0.19 MiB
显示代码纯文本
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;
  procedure work(t:longint);
    var
      i,j,l:longint;
    begin
      m:=0;
      l:=1;
      for i:=1 to n-1 do
          if i=t then
            begin
              m:=m+abs(a[l]-b[i]);
              inc(l);
              m:=m+abs(a[l]-b[i]);
              inc(l);
            end
           else
             begin
               m:=m+abs(a[l]-b[i]);
               inc(l);
             end;
    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
            work(i);
            if m<ans then ans:=m;
          end;
        writeln(ans);
        readln(s);
      end;
    close(input);close(output);
  end.