Pagini recente » Cod sursa (job #2371441) | Cod sursa (job #2512951) | Cod sursa (job #2398868) | Cod sursa (job #2095719) | Cod sursa (job #941912)
Cod sursa(job #941912)
#include <fstream>
using namespace std;
int main()
{
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n;
fin >> n;
int a[n];
pair<int,int> b = pair<int,int>(0,0);
for (int i = 0; i < n; ++i) {
fin >> a[i];
if (b.second == 0) b.first = a[i];
if (a[i] == b.first) b.second++;
else b.second--;
}
int elem = b.first, cnt = 0;
for (int i = 0; i < n; ++i)
if (a[i] == elem)
++cnt;
if (cnt >= n/2+1) fout << elem << ' ' << cnt;
else fout << -1;
return 0;
}