CF1833B.Restore the Weather

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

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 (1≤i≤n1 \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 ∣ai−c∣≤k|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, ∣a1−b1∣=∣1−2∣=1|a_1 - b_1| = |1 - 2| = 1, 1≤2=k1 \le 2 = k is satisfied;
  • On the 22nd day ∣a2−b2∣=∣3−2∣=1|a_2 - b_2| = |3 - 2| = 1, 1≤2=k1 \le 2 = k is satisfied;
  • On the 33rd day, ∣a3−b3∣=∣5−5∣=0|a_3 - b_3| = |5 - 5| = 0, 0≤2=k0 \le 2 = k is satisfied;
  • On the 44th day, ∣a4−b4∣=∣3−4∣=1|a_4 - b_4| = |3 - 4| = 1, 1≤2=k1 \le 2 = k is satisfied;
  • On the 55th day, ∣a5−b5∣=∣9−11∣=2|a_5 - b_5| = |9 - 11| = 2, 2≤2=k2 \le 2 = k is satisfied.

给你一个数组 aa,其中包含 Berlandia 过去 nn 天的天气预报数据。即,aia_i 表示第 ii 天(1≤i≤n1 \le i \le n)预测的气温。

你还被给定一个数组 bb,表示每天实际的气温值。但数组 bb 中的所有数值顺序是打乱的。

请确定哪一天对应哪个实际气温值,已知实际天气与预报之间的偏差从不超过 kk 度。换言之,若第 ii 天的实际气温为 cc,则恒有 ∣ai−c∣≤k|a_i - c| \le k。

例如,设数组 a=[1,3,5,3,9]a = [1, 3, 5, 3, 9],长度 n=5n = 5,且 k=2k = 2;另给定数组 b=[2,5,11,2,4]b = [2, 5, 11, 2, 4]。那么,为使 bib_i 对应第 ii 天的实际气温,我们可以将数组 bb 重排为 [2,2,5,4,11][2, 2, 5, 4, 11]。验证如下:

  • 第 11 天:∣a1−b1∣=∣1−2∣=1|a_1 - b_1| = |1 - 2| = 1,满足 1≤2=k1 \le 2 = k;
  • 第 22 天:∣a2−b2∣=∣3−2∣=1|a_2 - b_2| = |3 - 2| = 1,满足 1≤2=k1 \le 2 = k;
  • 第 33 天:∣a3−b3∣=∣5−5∣=0|a_3 - b_3| = |5 - 5| = 0,满足 0≤2=k0 \le 2 = k;
  • 第 44 天:∣a4−b4∣=∣3−4∣=1|a_4 - b_4| = |3 - 4| = 1,满足 1≤2=k1 \le 2 = k;
  • 第 55 天:∣a5−b5∣=∣9−11∣=2|a_5 - b_5| = |9 - 11| = 2,满足 2≤2=k2 \le 2 = k。

输入格式

The first line of input data contains a single integer tt (1≤t≤1041 \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 (1≤n≤1051 \le n \le 10^5) and kk (0≤k≤1090 \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 (−109≤ai≤109-10^9 \le a_i \le 10^9).

The third line of each test case contains exactly nn integers — elements of array bb (−109≤bi≤109-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 ∣ai−bi∣≤k|a_i - b_i| \le k is true for all ii.

输入数据的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn(1≤n≤1051 \le n \le 10^5)和 kk(0≤k≤1090 \le k \le 10^9)—— 分别表示天数,以及每天预期气温与实际气温之间的最大允许差值。

每个测试用例的第二行包含恰好 nn 个整数 —— 数组 aa 的元素(−109≤ai≤109-10^9 \le a_i \le 10^9)。

每个测试用例的第三行包含恰好 nn 个整数 —— 数组 bb 的元素(−109≤bi≤109-10^9 \le b_i \le 10^9)。

保证所有测试用例的 nn 值之和不超过 10510^5,且数组 bb 的元素总能被重新排列,使得对所有 ii 均满足不等式 ∣ai−bi∣≤k|a_i - b_i| \le k。

输出格式

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.

对每个测试用例,在单独的一行中输出恰好 nn 个数字——按正确顺序排列的每一天的气温值。

如果存在多个答案,则输出其中任意一个即可。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页