Pagini recente » Cod sursa (job #2450991) | Cod sursa (job #564742) | Cod sursa (job #1400040) | Cod sursa (job #509516) | Cod sursa (job #1423484)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
vector <int> v;
int main() {
int n, nr, cand = 0, cnt = 0;
fin >> n;
for (; n; n--) {
fin >> nr;
v.push_back(nr);
if (!cand) {
cand = nr;
cnt = 1;
} else if (nr == cand)
cnt++;
else cnt--;
if (!cnt)
cand = 0;
}
cnt = 0;
for (auto it : v)
if (it == cand)
cnt++;
if (cnt >= n / 2 + 1)
fout << cand << ' ' << cnt;
else fout << -1;
return 0;
}