Cod sursa(job #680404)
| Utilizator | Data | 15 februarie 2012 16:08:28 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 80 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
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.
