Cod sursa(job #1490361)
| Utilizator | Data | 23 septembrie 2015 12:39:52 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.69 kb |
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
using namespace std;
int n;
map<int,int> m;
vector<int> v;
int el=-1;
int k;
void read()
{
scanf("%d ",&n);
int x;
for(int i=0;i<n;i++)
{
scanf("%d ",&x);
m[x]++;
if(k==0)
el=x,k=1;
else if(el==x) k++;
else k--;
if(el==-1)
printf("-1");
}
}
int main()
{
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
read();
if(el!=-1)
if(m[el]>n/2)
printf("%d %d",el,m[el]);
else printf("-1");
return 0;
}
