Cod sursa(job #3339827)
| Utilizator | Data | 10 februarie 2026 13:28:55 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
int v[1000005];
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifndef LOCAL
freopen("elmaj.in", "r", stdin);
freopen("elmaj.out", "w", stdout);
#endif
int n; cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> v[i];
}
sort(v + 1, v + n + 1);
int i = 1, j = 1, cnt = 0, voted = -1;
while(i <= n) {
j = i + 1;
while(j <= n && v[j] == v[i])
++j;
if(j - i > n/2) {
voted = v[i];
cnt = j - i;
break;
}
i = j;
}
cout << voted << ' ' << cnt;
return 0;
}