Cod sursa(job #2133854)

Utilizator ctrohinCristina Trohin ctrohin Data 17 februarie 2018 13:21:48
Problema Elementul majoritar Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.65 kb
var a:array[1..1000000] of int64; i,n,j,x:int64;
begin read(n);
      i:=1;
      while i<=n do begin
                        read(a[i]);
                        inc(i);
                    end;
      i:=1;
      while i<=n do begin
                        j:=1;
                        while j<=n do begin
                                        if a[j]=a[i] then inc(x);
                                        inc(j);
                                       end;
                        if x=n div 2+1 then break else inc(i);
                       end;
      if x<>n div 2+1 then writeln(-1)
                      else writeln(a[i],' ',x);
end.