Pagini recente » Profil Al3ks1002 | Monitorul de evaluare | Cod sursa (job #2892392) | Cod sursa (job #397966) | Cod sursa (job #1065540)
//#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
const int MOD = 666013;
int n;
int el_maj, ap_max=0;
vector <pair <int, int> > hash[MOD];
inline void update(int val, int ap){
if (ap>ap_max){
ap_max = ap;
el_maj = val;
}
}
int in_hash(int val, int key){
int sz = hash[key].size();
for (int i = 0; i < sz; ++i)
if (hash[key][i].first == val)
return i;
return -1;
}
void put_output(){
ofstream out("elmaj.out");
//cout<<ap_max;
if ( ap_max >= n/2+1 ) out<<el_maj<<" "<<ap_max;
else out<<-1;
out.close();
}
int main(){
ifstream in("elmaj.in");
in>>n;
for (int i = 1; i<= n; ++i){
int val;
in>>val;
int key = val % MOD;
int poz = in_hash(val,key);
if (poz==-1){
hash[key].push_back(make_pair(val,1));
update(val,1);
}else{
hash[key][poz].second++;
update(hash[key][poz].first,hash[key][poz].second);
}
}
in.close();
return 0;
}