Pagini recente » Cod sursa (job #475352) | Cod sursa (job #3136793) | Cod sursa (job #2365411) | Cod sursa (job #3266700) | Cod sursa (job #730902)
Cod sursa(job #730902)
#include <fstream>
using namespace std;
const int MAX = 1000050;
int n, v[MAX], maj, contor;
int main()
{
ifstream in("elmaj.in");
ofstream out("elmaj.out");
in>>n;
for(int i = 1; i <= n; i++) in>>v[i];
for(int i = 1; i <= n; i++)
if(v[i] == maj)
contor++;
else
{
contor--;
if(contor < 0)
{
maj = v[i];
contor = 1;
}
}
contor = 0;
for(int i = 1; i <= n; i++) if(v[i] == maj) contor++;
if(contor >= (n / 2) + 1)
out<<maj<<" "<<contor;
else
out<<"-1";
return 0;
}