Cod sursa(job #771251)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 25 iulie 2012 12:36:00
Problema Congr Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.74 kb
Program congr;
 type tip=record
      v,p:longint;
      end;
var a,b:array [1..300000] of tip;
    st,sc:int64;
    aux:tip;
    b1,b2:array [1..1 shl 17] of char;
    i,n,p1,p2:longint;
    fi,fo:text;
begin
 assign(fi,'congr.in');
  assign(fo,'congr.out');
 settextbuf(fi,b1); settextbuf(fo,b2);
 reset(fi); rewrite(fo); readln(fi,n);
  for i:=1 to n do begin read(fi,a[i].v); a[i].p:=i; sc:=sc+a[i].v; end;
   for i:=n+1 to 2*n-1 do begin read(fi,b[i-n].v); b[i-n].p:=i; end;
 while sc mod n<>0 do begin
             p1:=random(n)+1;
             p2:=random(n-1)+1;
             sc:=sc-a[p1].v+b[p2].v;
             aux:=a[p1]; a[p1]:=b[p2]; b[p2]:=aux;
             end;
  for i:=1 to n do write(fo,a[i].p,' ');
 close(fo);
end.