You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int a1[N], a2[N], b1[N], b2[N], a[N], b[N];
int main()
{
int T, n, m;
scanf("%d", &T);
while (T--)
{
int ca1 = 0, ca2 = 0, cb1 = 0, cb2 = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < m; i++) scanf("%d", b + i);
for (int i = 0, x; i < n; i++)
{
scanf("%d", &x);
if (x)
a1[ca1++] = a[i];
else
a2[ca2++] = a[i];
}
for (int i = 0, x; i < m; i++)
{
scanf("%d", &x);
if (x)
b1[cb1++] = b[i];
else
b2[cb2++] = b[i];
}
sort(a1, a1 + ca1);
sort(a2, a2 + ca2);
sort(b1, b1 + cb1);
sort(b2, b2 + cb2);
int ans = 0;
for (int i = 0, j = 0; i < ca1 && j < cb2; j++)
if (a1[i] < b2[j])
ans++, i++;
for (int i = 0, j = 0; i < cb1 && j < ca2; j++)
if (b1[i] < a2[j])
ans++, i++;
printf("%d\n", ans);
}
return 0;
}