Pagini recente » Cod sursa (job #2725935) | Cod sursa (job #1943645) | Cod sursa (job #2053091) | Cod sursa (job #1950871) | Cod sursa (job #1072572)
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <assert.h>
using namespace std;
const string file = "elmaj";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
const int MODN = 66697;
vector<vector<pair<int, int> > > HashTable;
inline int hashit(int key)
{
return key % MODN;
}
int increment(int key)
{
int h = hashit(key);
for(vector<pair<int, int> >::iterator itr = HashTable[h].begin();
itr != HashTable[h].end();
itr++)
{
if(itr->first == key)
{
itr->second ++;
return itr->second;
}
}
HashTable[h].push_back(make_pair(key, 1));
return 1;
}
int main()
{
#ifdef ONLINE_JUDGE
ostream &fout = cout;
istream &fin = cin;
#else
fstream fout(outfile.c_str(), ios::out);
fstream fin(infile.c_str(), ios::in);
#endif
int N;
fin >> N;
HashTable.resize(MODN);
int element = 0;
int count = 0;
for(int i = 0; i < N; i++)
{
int x;
fin >> x;
int c = increment(x);
if(c > count)
{
count = c;
element = x;
}
}
if(count >= N / 2 + 1)
{
fout << element << " " << count << "\n";
}
else
{
fout << "-1\n";
}
#ifdef ONLINE_JUDGE
#else
fin.close();
fout.close();
#endif
}