Cod sursa(job #2548182)

Utilizator Arteni_CristiArteni Cristi Arteni_Cristi Data 16 februarie 2020 12:52:54
Problema Elementul majoritar Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.52 kb
var t:array[1..1000005] of longint;
    n,i,x,xp,mx:longint;
begin
assign(input,'elmaj.in'); reset(input);
assign(output,'elmaj.out'); rewrite(output);
readln(n);
for i:=1 to n do read(t[i]);
mx:=t[1]; x:=1;
for i:=2 to n do
 begin
  if x=0 then
   begin
    mx:=t[i];
    x:=1
   end else
    if t[i]=mx then inc(x) else dec(x)
 end;
if x>=0 then
 begin
  for i:=1 to n do
   if t[i]=mx then inc(xp);
   if xp>=n div 2+1 then writeln(mx,' ',xp) else writeln('-1')
 end;
close(input);
close(output)
end.