Two Merchants

 There are two merchants in the market. Initially, the first merchant has 

items for sale at distinct prices and the second merchant has items for sale at distinct prices

.

If you buy an item from a merchant, the prices of all remaining items for both merchants change in the following manner:

  • The cost of all the remaining items of the chosen merchant will increase by
  • .
  • The cost of all the remaining items of the other merchant will decrease by
    • .

    Note that prices may become negative during this process.

    For e.g. if

    and you buy the second item from the second merchant then the prices of remaining items will be as follows

    You can only buy an item if its cost is at most

    . Can you buy all items from both merchants in the market in some order?

    Input Format

    • The first line of the input contains a single integer
    - the number of test cases. The description of
  • test cases follows.
  • The first line of each test case contains three integers
  • , and
  • - the number of items of the first merchant, the number of items of the second merchant and the maximum cost of an item you can buy respectively.
  • The second line contains
  • space-separated integers
  • - the prices of items of first merchant.
  • The third line contains
  • space-separated integers
    • - the prices of items of second merchant.

    Output Format

    For each test case, output Yes if it is possible to buy all items from both merchants in the market in some order. Otherwise, output No.

    You may print each character of Yes and No in uppercase or lowercase (for example, the strings yEs, yes, Yes and YES will all be treated as identical).

    Constraints

  • for all
  • for all
  • the sum of
  • over all test cases does not exceed
  • the sum of
  • over all test cases does not exceed

    Sample Input 1

    6
    1 2 1
    1
    1 2
    2 1 2
    1 2
    1
    3 2 5
    1 2 4
    4 9
    3 3 7
    2 4 8
    1 4 8
    5 10 27
    3 6 17 28 30
    1 3 4 5 7 9 21 27 29 30
    9 4 21
    1 5 6 8 14 16 19 22 25
    2 9 23 27
    

    Sample Output 1

    YES
    YES
    NO
    YES
    YES
    NO
    

    Explanation

    Test case 1: One possible sequence of operations is shown below. The item we purchase in a given turn is highlighted in red.

    Test case 2: One possible sequence of operations is shown below. The item we purchase in a given turn is highlighted in red.

    Note that prices may become

    during this process and in such a case the item can still be bought.

    Test case 3: It can be shown that there is no way to buy the second item sold by Merchant

    regardless of the order in which we buy the items.

    Test case 4: One possible sequence of operations is shown below. The item we purchase in a given turn is highlighted in red.

  • Previous
    Next Post »