Pagini recente » Cod sursa (job #2320125) | Cod sursa (job #1581044) | Cod sursa (job #2686412) | Cod sursa (job #2455746) | Cod sursa (job #820547)
Cod sursa(job #820547)
var fi,fo:text;
n,i:int64;
a:array[1..1000001] of int64;
procedure citire;
begin
readln(fi,n);
for i:=1 to n do
read(fi,a[i]);
end;
procedure calculare;
var nr,cand,k:int64;
begin
cand:=-1; k:=0;
for i:=1 to n do
if (k=0) then begin cand:=a[i]; k:=1; end else
if (a[i]=cand) then inc(k) else dec(k);
if (cand<0) then begin writeln(fo,-1); halt; end;
nr:=0;
for i:=1 to n do
if (a[i]=cand) then inc(nr);
if (nr>n div 2) then writeln(fo,cand,' ', nr);
end;
BEGIN
assign(fi,'maj.in'); reset(fi);
assign(fo,'maj.out'); rewrite(fo);
citire;
calculare;
close(fi); close(fo);
END.