Pagini recente » Cod sursa (job #1098786) | Cod sursa (job #286350) | Cod sursa (job #1003592) | Cod sursa (job #2892958) | Cod sursa (job #1169021)
#include<fstream>
#define MOD 666013
#include<vector>
#include<algorithm>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
vector <int> G[MOD+2];
vector<pair<int,int> > P;
int nr,x,n,nrmax,pmax,ok;
int main(){
f>>n;
for(int i=1;i<=n;++i){
f>>x;
if(x==nrmax){
++P[pmax].second;
continue;
}
int poz=x%MOD;
G[poz].push_back(x);
if(G[poz].size()>=n/2){
int okk=1;
for(int j=0;j<P.size();++j){
if(P[j].first==x){
okk=0;
++P[j].second;
if(!nrmax && P[j].second>n/2){
pmax=j;
nrmax=x;
ok=1;
}
}
}
if(okk){
P.push_back(make_pair(x,0));
int nr=0;
for(int i=0;i<G[poz].size();++i)
if(G[poz][i]==x)
++nr;
P[P.size()-1].second=nr;
}
}
}
if(ok)
g<<nrmax<<" "<<P[pmax].second;
else
g<<-1;
return 0;
}