AcWing 3720. 数组重排--Java
原题链接
中等
作者:
卡曼橘
,
2021-06-23 19:38:11
,
所有人可见
,
阅读 204
import java.util.Scanner;
import java.util.HashSet;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T > 0)
{
int n = sc.nextInt();
int x = sc.nextInt();
HashSet set = new HashSet();
int[] a = new int[n];
int[] b = new int[n];
for(int i = 0 ; i < n; i ++)
a[i] = sc.nextInt();
for(int i = 0; i < n; i ++)
b[i] = sc.nextInt();
boolean f = true;
for(int i = 0; i < n ; i ++)//b[i]
{
int m = -1;
for(int j = 0; j < n; j ++)//a[j]
{
if(b[i] + a[j] <= x && !set.contains(j))
{
if(m == -1) m = j;
else
{
if(a[m] < a[j])
m = j;
}
}
}
if (m == -1)
{
f = false;
break;
}else
set.add(m);
}
if(f) System.out.println("Yes");
else System.out.println("No");
T --;
}
}
}