Cod sursa(job #2158590)
| Utilizator | Data | 10 martie 2018 14:13:34 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.7 kb |
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define nmax
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
vector< int > a;
int n,x,ok;
int main()
{
fin>>n;
for(int i = 1; i <= n ; i++)
{
fin>>x;
a.push_back(x);
}
sort(a.begin(),a.end());
int i=0;
while(i < n )
{
int j = i ;
while( j < n && a[j+1]==a[i])
j++;
if(j-i+1 > n / 2 )
{
ok=1;
fout<< a[i]<<" "<<j-1+1<<'\n';
break;
}
i=j+1;
}
if(!ok) fout<<-1;
return 0;
}
