Pagini recente » Cod sursa (job #2408684) | Cod sursa (job #2542761) | Cod sursa (job #2209377) | Cod sursa (job #2529221) | Cod sursa (job #680404)
Cod sursa(job #680404)
var
a:array[1..1000000] of int64;
i,j,k,n,p:longint;
cand:int64;
f,g:text;
begin
assign (f,'elmaj.in'); 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.