Pagini recente » Cod sursa (job #2738487) | Cod sursa (job #674299) | Cod sursa (job #610840) | Cod sursa (job #2018411) | Cod sursa (job #1497345)
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int main()
{
int sm, cnt, nr, a[1000001], m, r = 0;
fin >> m;
for (int i = 1; i<=m; i++)fin >> a[i];
sm = a[1];
cnt = 1;
for (int j = 2; j<=m; j++)
{
if (a[j]==sm)cnt++;
else cnt--;
if (cnt == 0)
{
sm = a[j];
if (j!=m)cnt = 1;
}
}
if (cnt != 0)
{
nr=0;
for (int j = 1; j<= m; j++)
if (a[j]==sm)nr++;
if (nr >= m/2+1) r++;
}
if (r == 0)fout << -1;
else fout << sm << ' ' << nr;
return 0;
}