先用map统计每种语言有多少科学家会,然后遍历每场电影,找到愉悦人数最多前提下,满足人数最多的电影。
#include <cstdio>
#include <map>
using namespace std;
int N,M,mova[200005],movs[200005];
map<int,int> lang;
int read()
{
int r=0;
char ch=getchar();
while(ch<'0' || ch>'9')ch=getchar();
while(ch>='0' && ch<='9')r=r*10+ch-'0',ch=getchar();
return r;
}
int main()
{
N=read();
for(int i=1;i<=N;i++)lang[read()]+=1;
M=read();
for(int i=1;i<=M;i++)mova[i]=read();
for(int i=1;i<=M;i++)movs[i]=read();
//bestI-目前最佳电影(要初始化为1)
//bestP-目前最多几人愉悦
//bestS-目前最多几人满意
int bestI=1,bestP=0,bestS=0;
for(int i=1;i<=M;i++)
{
int a=lang[mova[i]],s=lang[movs[i]];
if(a==bestP && s>bestS)bestI=i,bestS=s;
else if(a>bestP)bestI=i,bestP=a,bestS=s;
}
printf("%d",bestI);
}