1、a[N]保存所有红色石头的位置,用b[N]保存所有蓝色石头的位置
2、对a[N]和b[N]都进行sort排序
3、遍历每两个相邻蓝色石头之间有多少个红色石块,最多的那个即为答案
4、需要注意的是第一个蓝色石头之前的所有红色石块也可以是答案,最后一块蓝队石头之后的红色石头也可以是答案

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+10;
int n,m,res,T;
int a[N],b[N];
signed main()
{
    cin>>T;
    while(T--)
    {
        res=0;
        cin>>n>>m;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int j=1;j<=m;j++) cin>>b[j];
        sort(a+1,a+n+1);
        sort(b+1,b+n+1);
        b[0] = 0; // 添加虚拟的蓝色石头,第一块蓝色石头之前的所有红色石块也可以是答案
        b[m+1] = 1e9+1; // 添加虚拟的蓝色石头,最后一块蓝色石头之后的红色石头也可以是答案
        for(int i=0;i<=m;i++) // 遍历每两个蓝色石头之间有多少个红色石块,保留最多的那个即为答案
        {
            int l=upper_bound(a+1,a+n+1,b[i])-a;
            int r=lower_bound(a+1,a+n+1,b[i+1])-a;
            res=max(res,r-l);
        }
        if(res==0) cout<<"Impossible"<<endl;
        else cout<<res<<endl;
    }
}