Pagini recente » Cod sursa (job #1011541) | Cod sursa (job #1377295) | Cod sursa (job #1621804) | Cod sursa (job #252608) | Cod sursa (job #1284119)
#include <fstream>
#include <algorithm>
using namespace std;
int a[1000005];
int main()
{
int n, i, cnt, mx = 1, elmaj;
ifstream fin("elmaj.in");
fin >> n;
for(i = 1; i <= n; i++) fin >> a[i];
sort(a + 1, a + n + 1);
for(i = 2; i <= n; i++)
{
if(a[i] == a[i - 1]) cnt++;
else cnt = 1;
if(mx < cnt)
{
mx = cnt;
elmaj = a[i];
}
}
ofstream fout("elmaj.out");
if(mx < n / 2 + 1) fout << "-1";
else fout << elmaj << " " << mx;
fout.close();
return 0;
}