Pagini recente » Cod sursa (job #954232) | Cod sursa (job #636445)
Cod sursa(job #636445)
# include <algorithm>
# include <fstream>
using namespace std;
const char *FIN = "elmaj.in", *FOU = "elmaj.out";
const int MAX = 1000005;
int N, sol, V[MAX];
int main (void) {
ifstream f (FIN);
ofstream g (FOU);
f >> N;
for (int i = 0; i < N; ++i)
f >> V[i];
nth_element (V, V + N / 2, V + N);
for (int i = 0; i < N; ++i)
if (V[i] == V[N / 2])
sol += 1;
if (sol >= N / 2) g << V[N / 2] << " " << sol;
else g << "-1";
}