CF1833B.Restore the Weather

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Restore the Weather

You are given an array aa containing the weather forecast for Berlandia for the last nn days. That is, aia_i — is the estimated air temperature on day ii (1in1 \le i \le n).

You are also given an array bb — the air temperature that was actually present on each of the days. However, all the values in array bb are mixed up.

Determine which day was which temperature, if you know that the weather never differs from the forecast by more than kk degrees. In other words, if on day ii the real air temperature was cc, then the equality aick|a_i - c| \le k is always true.

For example, let an array aa = [1,3,5,3,91, 3, 5, 3, 9] of length n=5n = 5 and k=2k = 2 be given and an array bb = [2,5,11,2,42, 5, 11, 2, 4]. Then, so that the value of bib_i corresponds to the air temperature on day ii, we can rearrange the elements of the array bb so: [2,2,5,4,112, 2, 5, 4, 11]. Indeed:

  • On the 11st day, a1b1=12=1|a_1 - b_1| = |1 - 2| = 1, 12=k1 \le 2 = k is satisfied;
  • On the 22nd day a2b2=32=1|a_2 - b_2| = |3 - 2| = 1, 12=k1 \le 2 = k is satisfied;
  • On the 33rd day, a3b3=55=0|a_3 - b_3| = |5 - 5| = 0, 02=k0 \le 2 = k is satisfied;
  • On the 44th day, a4b4=34=1|a_4 - b_4| = |3 - 4| = 1, 12=k1 \le 2 = k is satisfied;
  • On the 55th day, a5b5=911=2|a_5 - b_5| = |9 - 11| = 2, 22=k2 \le 2 = k is satisfied.

Input

The first line of input data contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains two integers nn (1n1051 \le n \le 10^5) and kk (0k1090 \le k \le10^9) — the number of days and the maximum difference between the expected and actual air temperature on each day.

The second line of each test case contains exactly nn integers — elements of array aa (109ai109-10^9 \le a_i \le 10^9).

The third line of each test case contains exactly nn integers — elements of array bb (109bi109-10^9 \le b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5, and that the elements of array bb can always be rearranged so that the equality aibik|a_i - b_i| \le k is true for all ii.

Output

On a separate line for each test case, output exactly nn numbers — the values of air temperature on each of the days in the correct order.

If there is more than one answer — output any of them.

Samples

3
5 2
1 3 5 3 9
2 5 11 2 4
6 1
-1 3 -2 0 -5 -1
-4 0 -1 4 0 0
3 3
7 7 7
9 4 8
2 2 5 4 11
0 4 -1 0 -4 0
8 4 9

在线编程 IDE

建议全屏模式获得最佳体验