1 条题解

  • 0
    @ 2021-6-15 10:13:26

    Pascal :

    var
    n,m,i,j,k:integer;
    a,b,c:array[1..10000]of integer;
    
    procedure qsort(l,h:integer);
     var i,j,t,m:integer;
    begin
     i:=l;
     j:=h;
     m:=a[(i+j) div 2];
     repeat
      while a[i]<m do inc(i);
      while m<a[j] 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 j>l then qsort(l,j);
     if i<h then qsort(i,h);
    end;
    
    begin
    readln(n); m:=0;k:=0;
    for i:=1 to n do read(c[i]);
    for i:=1 to n do read(b[i]);
    for i:=1 to n do
     for j:=1 to n do begin m:=m+1; a[m]:=abs(c[i]-b[j]);dec(a[m]); end;
    qsort(1,m);
    for i:=m downto m-n+1 do k:=k+a[i];
    writeln(k);
    end.
    
    
    • 1

    信息

    ID
    455
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者