P22481 [CodeChef] TWOMERCHANTS
提高+
题目描述

There are two merchants in the market. Initially, the first merchant has N items for sale at distinct prices $A_{1}, A_{2}, \ldots, A_{N}$ and the second merchant has M items for sale at distinct prices $B_{1}, B_{2}, \ldots, B_{M}$.

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 1.
The cost of all the remaining items of the other merchant will decrease by 1.

Note that prices may become negative during this process.

For e.g. if A = [3, 4, 5], B = [1, 3, 4] and you buy the second item from the second merchant then the prices of remaining items will be as follows A = [2, 3, 4], B = [2, -, 5]

You can only buy an item if its cost is at most C. 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 T - the number of test cases. The description of T test cases follows.
  • The first line of each test case contains three integers N, M and C - 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 $N space-separated integers A_{1} < A_{2} < \cdots < A_{N} -$ the prices of items of first merchant.
  • The third line contains $M space-separated integers B_{1} < B_{2} < \cdots < B_{M} -$ 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 ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N, M ≤ 5 \cdot 10^{5}$
$1 ≤ A_{i}, B_{i}, C ≤ 10^{9}$
$A_{i} < A_{i + 1}$ for all $1 ≤ i < N$
$B_{i} < B_{i + 1}$ for all $1 ≤ i < M$
- the sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$
- the sum of $M$ over all test cases does not exceed $5 \cdot 10^{5}$

----- 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 1 ------
Test case 1: One possible sequence of operations is shown below. The item we purchase in a given turn is highlighted in red.

  • $A = [{\color{red}1}], B = [1, 2]$
  • $A = [-], B = [0, {\color{red}1}]$
  • $A = [-], B = [{\color{red}1}, -]$

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

  • $A = [1, {\color{red}2}], B = [1]$
  • $A = [{\color{red}2}, -], B = [0]$
  • $A = [-, -], B = [{\color{red}-1}]$

Note that prices may become $\textbf{negative}$ 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 $2$ 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.

  • $A = [{\color{red}2}, 4, 8], B = [1, 4, 8]$
  • $A = [-, 5, 9], B = [0, 3, {\color{red}7}]$
  • $A = [-, 4, 8], B = [1, {\color{red}4}, -]$
  • $A = [-, 3, {\color{red}7}], B = [2, -, -]$
  • $A = [-, {\color{red}4}, -], B = [1, -, -]$
  • $A = [-, -, -], B = [{\color{red}0}, -, -]$
输入格式

见题面

输出格式

见题面

样例输入
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
样例输出
YES YES NO YES YES NO