Cod sursa(job #3349776)
| Utilizator | Data | 2 aprilie 2026 14:51:59 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | py | Status | done |
| Runda | Teme Pregatire ACM Unibuc 2013 | Marime | 0.41 kb |
import random
with open("elmaj.in") as f:
n = int(f.readline())
v = list(map(int, f.readline().split()))
gasit = False
for _ in range(30):
x = random.choice(v)
cnt = v.count(x)
if cnt >= n//2+1:
with open("elmaj.out", "w") as g:
g.write(f"{x}{cnt}")
gasit = True
break
if not gasit:
with open("elmaj.out", "w") as g:
g.write("-1")