Pagini recente » Cod sursa (job #2443290) | Cod sursa (job #2066359) | Cod sursa (job #2909871) | Cod sursa (job #639184) | Cod sursa (job #680409)
Cod sursa(job #680409)
var
a:array[1..1000000] of int64;
i,k,n,p:longint;
cand:int64;
f,g:text;
buf1:array[1.. 1 shl 17] of char;
begin
assign (f,'elmaj.in'); settextbuf(f, buf1);
assign(g,'elmaj.out');
reset(f);rewrite(g);
read(f,n);
k:=0; cand:=-1;
for i:=1 to n do
begin
read(f,a[i]);
if k=0 then
begin
k:=1;
cand:=a[i];
end
else if a[i]=cand then k:=k+1
else k:=k-1;
end;
p:=0;
for i:=1 to n do
if a[i]=cand then p:=p+1;
if p>n div 2 then write(g,cand,' ',p)
else write(g,-1);
close(f); close(g);
end.