Pagini recente » Cod sursa (job #2742871) | Cod sursa (job #1488372) | Cod sursa (job #1735089) | Cod sursa (job #1545968) | Cod sursa (job #1865868)
#include <fstream>
#define nmax 1000001
#define hg 1<<10
#define verf ++poz == hg ? fin.read (ch, hg), poz = 0 : 0
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int n,val,ap,x,poz;
char ch[hg];
inline void cit( int &x )
{
if (ch[0] == '\0') fin.read (ch, hg) ;
else for (; ch[poz] < '0' || ch[poz] > '9' ; verf) ;
for (x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf) ;
}
int main()
{
int i;
cit(n);
for(i=1; i<=n; i++)
{
cit(x);
if(x==val)
ap++;
else ap--;
if(ap<0)
{
val=x;
ap=1;
}
}
ap=0;
fin.seekg(0);
cit(n);
for(i=1; i<=n; i++)
{
cit(x);
if(x==val)
ap++;
}
if(ap>=n/2+1)
fout<<val<<' '<<ap;
else fout<<-1;
fin.close();
fout.close();
return 0;
}