Cod sursa(job #1101761)
Utilizator | Mihai Chihai Mihai_Chihai | Data | 8 februarie 2014 23:42:15 |
---|---|---|---|
Problema | Elementul majoritar | Scor | 80 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
program el_maj;
const nmax=1000005;
var a:array[1..nmax] of longint;
n,i,k,cand,nr,x:longint;
begin
assign(input,'elmaj.in');
reset(input);
assign(output,'elmaj.out');
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
cand:=-1;
k:=0;
for i:=1 to n do
begin
if k=0 then begin cand:=a[i]; k:=1; end
else
if a[i]=cand then k:=k+1
else k:=k-1;
end;
nr:=0;
for i:=1 to n do if a[i]=cand then nr:=nr+1;
if nr>=n div 2+1 then write(cand,' ',nr)
else write(-1);
CLOSE(OUTPUT);
END.