Pagini recente » Cod sursa (job #1403210) | Cod sursa (job #611832) | Cod sursa (job #1081244) | Cod sursa (job #214168) | Cod sursa (job #2253013)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int main() {
int n;
f >> n;
vector<int> elems;
int elem;
for (int i = 0; i < n; i++) {
f >> elem;
elems.push_back(elem);
}
pair<int, int> possib = make_pair(elems.front(), 1);
for (auto it = elems.begin() + 1; it != elems.end(); ++it) {
if (*it == possib.first)
possib.second += 1;
else {
possib.second -= 1;
if (possib.second == 0) {
possib.first = *it;
possib.second = 1;
}
}
}
int count = 0;
for (auto el : elems) {
if (el == possib.first)
count += 1;
}
if (count >= elems.size() / 2 + 1)
g << possib.first << ' ' << count;
else
g << -1;
}