Pagini recente » Profil Sebi_geo | Monitorul de evaluare | Statistici Gigel Gogu (Account451) | Istoria paginii utilizator/chise_b | Cod sursa (job #2363864)
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
const int NMAX = 1000005;
int N, elmaj, cnt;
int v[NMAX];
int main()
{
fin >> N;
for(int i = 1; i <= N; i++)
fin >> v[i];
elmaj = v[1];
cnt = 1;
for(int i = 2; i <= N; i++)
{
if(v[i] == elmaj)
cnt++;
else
{
cnt--;
if(cnt == 0)
{
elmaj = v[i];
cnt = 1;
}
}
}
cnt = 0;
for(int i = 1; i <= N; i++)
if(v[i] == elmaj)
cnt++;
if(cnt > N / 2)
fout << elmaj << ' ' << cnt << '\n';
else
fout << -1 << '\n';
return 0;
}