Pagini recente » Cod sursa (job #898222) | Cod sursa (job #285168) | Cod sursa (job #1910901) | Cod sursa (job #595025) | Cod sursa (job #2418106)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int main()
{
ios_base::sync_with_stdio(0);
in.tie(0);
out.tie(0);
int n;
in >> n;
unordered_map<int,int> um;
int maj = n/2 + 1;
int elem = 0;
for(int i = 0; i < n; i++)
{
int tmp;
in >> tmp;
int fr = ++um[tmp];
if(!elem && fr >= maj) elem = tmp;
}
if(elem) out << elem << ' ' << um[elem];
else out << -1;
return 0;
}