Pagini recente » Cod sursa (job #2779642) | Cod sursa (job #2673205) | Cod sursa (job #576816) | Cod sursa (job #583163) | Cod sursa (job #1171671)
#include <fstream>
#include <map>
using namespace std;
int N;
map<int, int> mappings;
map<int,int>::iterator it;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main(){
fin >> N;
int x, count = -1, who = -1;
for(int i = 0; i < N; i++){
fin >> x;
it = mappings.find(x);
if(it == mappings.end()){
mappings[x] = 1;
}else{
mappings[x] += 1;
}
if(mappings[x] > count){
count = it->second;
who = x;
}
}
if(count >= N/2 + 1)
fout << who << " " << count << "\n";
else
fout << "-1\n";
return 0;
}