Pagini recente » Cod sursa (job #2415407) | Cod sursa (job #1706793) | Cod sursa (job #1491733) | Cod sursa (job #1311020) | Cod sursa (job #2605294)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int n;
int a[1000007];
int elem, cont;
int main()
{
fin >> n;
for(int i = 0; i < n; i++)
{
fin >> a[i];
if(cont == 0)
elem = a[i];
else if(elem == a[i])
cont++;
else
cont--;
}
int conttemp = 0;
for(int i = 0; i < n; i++)
{
if(a[i] == elem)
conttemp++;
}
if(conttemp >= n/2 + 1)
fout << elem << " " << conttemp;
else
fout << "-1";
return 0;
}