Pagini recente » Cod sursa (job #2626550) | Cod sursa (job #250835) | Cod sursa (job #2640754) | Cod sursa (job #525734) | Cod sursa (job #709959)
Cod sursa(job #709959)
#include <fstream>
#include <algorithm>
using namespace std;
int v[1000001];
int main()
{
ifstream f("elmaj.in");
ofstream g("elmaj.out");
bool ok=false;
int n, j, i, contor=1, max=0;
f>>n;
for(i=1; i<=n; i++)
{
f>>v[i];
}
sort(v+1, v+n+1);
for(i=n; i>1; i--)
{
if(v[i]==v[i-1])
contor++;
else
contor=1;
if(contor==n/2+1)
{
ok=true;
g<<v[i];
}
if(contor>max)
max=contor;
}
if(ok)
g<<" "<<max;
if(!ok)
g<<-1;
}