Pagini recente » Cod sursa (job #1978898) | Cod sursa (job #2497358) | Istoria paginii runda/lotj1/clasament | Cod sursa (job #888174) | Cod sursa (job #2461285)
# include <fstream>
# include <map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main()
{
int n, x, ok = 0;
int max = 0, maxv = 0, find = 0;
map<int, int>dictionar;
map<int, int>::iterator aux;
fin >> n;
for (int i = 0; i < n; i++)
{
fin >> x;
aux = dictionar.find(x);
if (aux!=dictionar.end())
{
aux->second++;
if (aux->second > n/2)
{
find = 1;
max = x;
maxv = aux->second;
}
}
else
dictionar.insert(pair<int, int >(x, 1));
}
if (find)
fout << max << " " << maxv;
else
fout << "-1";
return 0;
}