QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9681. Cat Food

Statistics

You have $n$ kittens at home. At mealtime, your cats are hungry, and each one needs to eat at least $m$ grams of cat food to be full.

You have two types of cat food: premium cat food and regular cat food.

  • Premium cat food tastes very good, so when you open a bag of premium cat food, all the kittens that are not yet full will scramble for it. In the end, any one of the kittens that are not yet full might snatch this bag and eat all the cat food in it.
  • Regular cat food has an average taste, so when you open a bag of cat food and place it in front of a specific kitten, other kittens will not scramble for it, and this kitten will eat all the cat food in the bag.

In both cases, even if the kitten that possesses the cat food only needs a portion of the bag to be full, it will still eat the entire bag.

Your cat food is running out. You have $n$ bags of premium cat food, where the $i$-th bag contains $a_i$ grams; you also have $n$ bags of regular cat food, where the $i$-th bag contains $b_i$ grams. The total weight of all cat food is exactly $n \times m$, which is the total weight of cat food required for all kittens to be full. At the same time, the weight of the cat food in every bag is an integer between $1$ and $m - 1$.

To feed all the kittens, you can choose one bag of cat food to open at a time, wait for it to be finished, and then open the next one, until all the cat food is consumed. You can decide the order in which to open the remaining cat food and which kitten to place the regular cat food in front of, based on the current consumption status.

You want to know if there exists a feeding strategy such that, regardless of which hungry kitten snatches the premium cat food each time it is opened, all kittens will eventually be full.

Input

The input is read from the file catfood.in.

This problem contains multiple test cases. The first line contains a positive integer $T$ representing the number of test cases. For each test case: The first line contains two positive integers $n$ and $m$, representing the number of kittens and the grams of cat food each kitten needs. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ describing the weights of the $n$ bags of premium cat food. The third line contains $n$ integers $b_1, b_2, \dots, b_n$ describing the weights of the $n$ bags of regular cat food.

Output

The output is written to the file catfood.out. For each test case, output a single line containing a string: if a strategy satisfying the conditions exists, output Yes, otherwise output No.

Examples

Input 1

2
2 90
60 20
70 30
2 10
3 5
6 6

Output 1

Yes
No

Note 1

In the first test case, you can first open the premium cat food weighing 60 grams. Regardless of which kitten eats it, open the regular cat food weighing 30 grams and feed it to the same kitten; this kitten will then be full. Next, open the premium cat food weighing 20 grams, which will be eaten by the remaining kitten. Finally, open the regular cat food weighing 70 grams and feed it to this kitten. Thus, both kittens have eaten 90 grams of cat food and are full. In the second test case, it can be proven that no strategy exists to feed all the kittens.

Examples 2

See catfood/catfood2.in and catfood/catfood2.ans in the contestant directory.

Note 2

This example satisfies special property B.

Constraints

For all test cases, it is guaranteed that: $1 \le T \le 50$; $1 \le n \le 40000$, $2 \le m \le 10^5$; For any $1 \le i \le n$, $1 \le a_i, b_i \le m - 1$; $\sum_{i=1}^n a_i + \sum_{i=1}^n b_i = nm$.

Test Case ID $n \le$ Special Property
1 1
2 ~ 4 2 None
5 ~ 7 5
8, 9 $4 \times 10^4$ A
10 ~ 16 $4 \times 10^4$ B
17 ~ 20 $4 \times 10^4$ None

Special property A: Guaranteed $m = 3$. Special property B: Guaranteed that the weights of any two bags of cat food are distinct, i.e., for any $1 \le i < j \le n$, $a_i \neq a_j$, $b_i \neq b_j$, and for any $1 \le i, j \le n$, $a_i \neq b_j$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.