NITK05 - FRUITS AND VEGETABLE
John is in a Market buying some vegetables and fruits. There N variety each of Vegetables and fruits available. The price of each different vegetable is stored in an integer array A while that of each different fruit is stored in an integer array B. Each array containing N integers. The size of the array is <= 1000. The vegetables and fruits are in any order and you can permute the order of the elements in the arrays.
Now for the real question - is there an arrangement of the Fruits and Vegetables such that price of Ai+Bi>=K for all i where Ai denotes the ith Vegetable in the array A. Bi denotes the ith Fruit in the array B. K is the money present in John's Wallet.
The first line contains the an integer T denoting the number of test-cases. T test cases follow. Each test case is given in the following format.
The first line contains two integers, N and K. The second line contains N integers separated by a single space, denoting A array. The third line describes B array in a same format.
1 <= T <= 10
1 <= N <= 1000
1 <= K <= 109
0 <= Ai, Bi <= 109
or each test case, if there is such arrangement exists output “YES”, otherwise “NO” (quotes for clarity).
2 3 10 2 1 3 7 8 9 4 5 1 2 2 1 3 3 3 4Explanation:
The first input has 3 elements in Array A and Array B, we see that the one of the arrangements,3 2 1 and 7 8 9 has each pair of elements (3+7, 2 + 8 and 9 + 1) summing upto 10 and hence the answer is “YES”.
The second input has B array with three 3s. So, we need at least three numbers in A to be greater than 1.As its not the case, the answer is “NO”.