CF1833B.Restore the Weather

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

输入格式

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 .

输出格式

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.

输入输出样例

  • 输入#1

    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

    输出#1

    2 2 5 4 11
    0 4 -1 0 -4 0
    8 4 9
首页