Pagini recente » Cod sursa (job #3330129) | Cod sursa (job #465690) | Cod sursa (job #3355748) | Cod sursa (job #875133) | Cod sursa (job #3349525)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
srand(time(0));
int n;
fin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
fin >> v[i];
int k = 20;
int elem = 0, nr_ap = 0;
bool ok = false;
for (int i = 0; i < k; i++) {
int idx = rand() % n;
int ap = 0;
for (int j = 0; j < n; j++)
if (v[j] == v[idx])
ap++;
if (ap > n / 2) {
elem = v[idx];
nr_ap = ap;
ok = true;
break;
}
}
if (!ok)
fout << -1;
else
fout << elem << " " << nr_ap;
return 0;
}