In computer science, the 0/1 Knapsack problem is a classic challenge: given a set of items, each with a weight and a value, choose a subset of items so that the total weight does not exceed a given limit, and the total value is as large as possible.
This problem is NP-hard. When the range of weights is relatively small, it can be solved exactly using the well-known dynamic programming algorithm. However, when both the weight and value ranges are very large, up to $$$10^9$$$ for example, heuristic approaches are needed to obtain good (though not necessarily optimal) solutions.
Two researchers, Alice and Bob, are studying simple and fast "heuristic" algorithms that give good results for such large-scale knapsack instances. Each of them uses a greedy strategy:
Now, Alice and Bob are given a dataset of $$$n$$$ items indexed from $$$1$$$ to $$$n$$$ and a knapsack with capacity $$$W$$$. However, some data is missing. For each item, its weight $$$w_i$$$ and value $$$r_i$$$ are given, but at most one of these two values might be unknown.
Your task is to assign a positive integer to each unknown value so that the set of items chosen by Alice is exactly the same as the set of items chosen by Bob (the order does not matter).
The first line contains an integer $$$T$$$ ($$$1 \le T \le 100$$$), denoting the number of test cases.
For each of the test cases, the first line inputs two integers $$$n, W$$$ ($$$1 \le n \le 3000$$$, $$$1 \le W \le 10^9$$$), denoting the number of items and the knapsack capacity.
The second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$), denoting the weights of the items. If $$$w_i = 0$$$, this parameter is unknown.
The third line contains $$$n$$$ integers $$$r_1, r_2, \ldots, r_n$$$ ($$$0 \le r_i \le 10^9$$$), denoting the values of the items. If $$$r_i = 0$$$, this parameter is unknown. It is guaranteed that for each item, at most one of the two values is unknown.
It is guaranteed that $$$\sum n \le 3000$$$ over all test cases.
For each test case, if there exists a valid assignment of positive integers to the unknown values that makes Alice's and Bob's chosen item sets identical, print $$$\texttt{Yes}$$$ in the first line. Then print all $$$w_i$$$ ($$$1 \le w_i \le$$$ $$$10^9$$$) in the second line separated by spaces, and print all $$$r_i$$$ ($$$1 \le r_i \le$$$ $$$10^9$$$) in the third line separated by spaces, which denotes a possible valid assignment. Otherwise, print $$$\texttt{No}$$$ in a single line.
Note that the maximum limits of $$$w_i$$$ and $$$r_i$$$ are both $$$10^9$$$, as same as the input limits. Either Yes or No is case-insensitive, which means you can print $$$\texttt{YeS}$$$, $$$\texttt{yEs}$$$, $$$\texttt{nO}$$$, etc.
63 50 2 32 4 03 52 3 04 0 23 10000000000 0 10000000002 3 15 10 1 1 1 03 8 0 7 95 10000000000 0 0 1 01 9 3 9 103 1000000000500000001 500000000 01000000000 999999998 1
Yes3 2 32 4 1Yes2 3 24 1 2Yes1000000000 999999999 10000000002 3 1Yes1000000000 1 1 1 10000000003 8 1 7 9Yes1000000000 1000000000 1000000000 1 9999999991 9 3 9 10No
For the first test case of the example, Alice takes the second item and then the first; Bob also takes the second and then the first.
For the second test case, Alice and Bob both take the first and the third items.
For the last test case, there is no solution.