Meaning of the questions:
The number given the number of boys, girls, and each person's height and preferences.
Some boys like tall girls, some boys like short girls, girls, too.
Only between heterosexual pairing, pairing up to ask a few pairs.
answer:
Open four storage arrays are four kinds of people, different preferences only to heterosexual pairing, paired twice to double under the standard method.
#include <bits / STDC ++ H.> the using namespace STD; const int MAXN = 1e6 + 15 ; int A [MAXN]; int B [MAXN]; Vector < int V1>; // like shorter than their female Vector < int > V2; // like higher than their female Vector < int > V3; // like shorter than their male Vector < int > V4; // like higher than their male int T; int N, M; int P [MAXN ]; int main () { Scanf ( " % D ",&T); while (T--) { scanf("%d%d",&N,&M); for (int i=1;i<=N;i++) scanf("%d",&a[i]); for (int i=1;i<=M;i++) scanf("%d",&b[i]); v1.clear(); v2.clear(); v3.clear(); v4.clear(); for (int i=1;i<=N;i++) { scanf("%d",&p[i]); if (p[i]==0) v1.push_back(a[i]); else v2.push_back(a[i]); } for (int i=1;i<=M;i++) { scanf("%d",&p[i]); if (p[i]==0) v3.push_back(b[i]); else v4.push_back(b[i]); } int ans=0; sort(v1.begin(),v1.end()); sort(v4.begin(),v4.end()); for (int i=0,j=0;i<v1.size()&&j<v4.size();) { if (v1[i]>v4[j]) { ans++; i++,j++; } else i++; } sort(v2.begin(),v2.end()); sort(v3.begin(),v3.end()); for (int i=0,j=0;i<v2.size()&&j<v3.size();) { if (v3[j]>v2[i]) { ans++; i++,j++; } else j++; } printf ("%d\n",ans); } return 0; }