#include <iostream>
using namespace std;
void CheckForPair(int b[], int g[], int m, int n)
{
int i = 0, j = 0;
while(i < m && j < n)
{
if(b[i] <= g[j])
{
cout << "No" << endl;
return;
}
++i;
++j;
}
cout << "Yes" << endl;
}
int Partition(int a[], int low, int high)
{
int pivot = a[low];
int i = low;
int j = high;
while(i < j)
{
while(a[i] <= pivot && i <= high-1)
++i;
while(a[j] > pivot && j >= low+1)
--j;
if(i < j)
swap(a[i], a[j]);
}
swap(a[low], a[j]);
return j;
}
void QuickSort(int a[], int low, int high)
{
if(low < high)
{
int pivotIndex = Partition(a, low, high);
QuickSort(a, low, pivotIndex-1);
QuickSort(a, pivotIndex+1, high);
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
int m, n;
cin >> m >> n;
if(m > n)
{
cout << "No" << endl;
continue;
}
int b[m], g[n];
for(int i = 0; i < m; ++i)
cin >> b[i];
for(int i = 0; i < n; ++i)
cin >> g[i];
QuickSort(b, 0, m-1);
QuickSort(g, 0, n-1);
CheckForPair(b, g, m, n);
}
return 0;
}
Comments