Pagini recente » Cod sursa (job #607758) | Cod sursa (job #1387822) | Cod sursa (job #2273626) | Cod sursa (job #635654) | Cod sursa (job #1851494)
#include <fstream>
using namespace std;
ifstream fin ( "elmaj.in" );
ofstream fout ( "elmaj.out" );
int a[1000001];
int main()
{ int n, i, maj, vot = 1, ct = 0;
fin >> n;
for ( i = 1; i <= n; i++ )
fin >> a[i];
fin.close();
maj = a[1];
for ( i = 2; i <= n; i++ )
if ( a[i] == maj ) vot++;
else if ( vot > 0 ) vot--;
else { maj = a[i];
vot = 1;
}
for ( i = 1; i <= n; i++ )
if ( a[i] == maj ) ct++;
if ( ct >= n / 2 + 1 )
fout << maj << " " << ct;
else fout << -1;
fout.close();
return 0;
}