Cod sursa(job #1239523)
Utilizator | Data | 9 octombrie 2014 10:15:20 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
int a[86]={0};
int main()
{
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int n,ok=1,mx=0,x;
f >> n;
f >> x;
mx=x;
for(int i=1;i<=n-1;++i)
{
f >> x;
if(ok==0)
{
mx=x;
}
if(x==mx)
{
++ok;
}
else --ok;
}
if(ok>=0) g << mx <<" " << (n/2)+ok/2;
else g << "-1";
return 0;
}