题目描述
There are two $n$-element arrays of integers, $A$ and $B$. Permute them into some $A^{\prime}$ and $B^{\prime}$ such that the relation $A^{\prime}[i]+B^{\prime}[i]\ge k$ holds for all $i$ where $0\leq i<n$.
There will be $q$ queries consisting of $A$, $B$, and $k$. For each query, return YES if some permutation $A^{\prime}$ , $B^{\prime}$ satisfying the relation exists. Otherwise, return NO.
Example
$A=[0,1]$
$B=[0,2]$
$k=1$
A valid $A^{\prime}$,$B^{\prime}$ is $A^{\prime}=[1,0]$and $B^{\prime}=[0,2]$:$1+0\geq1$ and $0+2\geq1$. Return YES.
Function Description
Complete the twoArrays function in the editor below. It should return a string, either YES or NO.
twoArrays has the following parameter(s):
int k: an integer
int A[n]: an array of integers
int B[n]: an array of integers
Returns
- string: either YES or NO
Input Format
The first line contains an integer $q$, the number of queries.
The next $q$ sets of $3$ lines are as follows:
The first line contains two space-separated integers $n$ and $k$, the size of both arrays $A$ and $B$, and the relation variable.
The second line contains $n$ space-separated integers $A[i]$.
The third line contains $n$ space-separated integers $B[i]$.
Constraints
$1\leq q\leq10$
$1\leq n\leq1000$
$1\leq k\leq10^9$
$0\le A[i],B[i]\le10^9$
Sample Input
STDIN Function
----- --------
2 q = 2
3 10 A[] and B[] size n = 3, k = 10
2 1 3 A = [2, 1, 3]
7 8 9 B = [7, 8, 9]
4 5 A[] and B[] size n = 4, k = 5
1 2 2 1 A = [1, 2, 2, 1]
3 3 3 4 B = [3, 3, 3, 4]
Sample Output
YES
NO
Explanation
There are two queries:
Permute these into $A^{\prime}=[1,2,3]$and $B^{\prime}=[9,8,7]$ so that the following statements are true:
$A[0]+B[1]=1+9=10\ge k$
$A[1]+B[1]=2+8=10\ge k$
$A[2]+B[2]=3+7=10\geq k$
$A=[1,2,2,1]$, $B=[3,3,34]$, and $k=5$. To permute $A$ and $B$ into a valid $A^{\prime}$ and $B^{\prime}$, there must be at least three numbers in $A$ that are greater than $1$.
输入格式
见题面
输出格式
见题面