Pagini recente » Cod sursa (job #1420816) | Cod sursa (job #1691565) | Cod sursa (job #1141018) | Cod sursa (job #1646251) | Cod sursa (job #3203186)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
int n,cnt,elem,nr;
vector<int> A;
int main()
{
cin>>n;
A.resize(n+1);
cin>>A[0];
elem=A[0];
cnt=1;
for(int i=1;i<n;i++)
{
cin>>A[i];
if(A[i]==elem)
cnt++;
else
cnt--;
if(cnt==-1)
{
elem=A[i];
cnt=1;
}
}
for(int i=0;i<n;i++)
if(A[i]==elem)
nr++;
if(nr>n/2)
cout<<elem<<" "<<nr;
else
cout<<-1;
return 0;
}