CF1833B.Restore the Weather
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a containing the weather forecast for Berlandia for the last n days. That is, ai — is the estimated air temperature on day i (1≤i≤n).
You are also given an array b — the air temperature that was actually present on each of the days. However, all the values in array b are mixed up.
Determine which day was which temperature, if you know that the weather never differs from the forecast by more than k degrees. In other words, if on day i the real air temperature was c, then the equality ∣ai−c∣≤k is always true.
For example, let an array a = [1,3,5,3,9] of length n=5 and k=2 be given and an array b = [2,5,11,2,4]. Then, so that the value of bi corresponds to the air temperature on day i, we can rearrange the elements of the array b so: [2,2,5,4,11]. Indeed:
- On the 1st day, ∣a1−b1∣=∣1−2∣=1, 1≤2=k is satisfied;
- On the 2nd day ∣a2−b2∣=∣3−2∣=1, 1≤2=k is satisfied;
- On the 3rd day, ∣a3−b3∣=∣5−5∣=0, 0≤2=k is satisfied;
- On the 4th day, ∣a4−b4∣=∣3−4∣=1, 1≤2=k is satisfied;
- On the 5th day, ∣a5−b5∣=∣9−11∣=2, 2≤2=k is satisfied.
给你一个数组 a,其中包含 Berlandia 过去 n 天的天气预报数据。即,ai 表示第 i 天(1≤i≤n)预测的气温。
你还被给定一个数组 b,表示每天实际的气温值。但数组 b 中的所有数值顺序是打乱的。
请确定哪一天对应哪个实际气温值,已知实际天气与预报之间的偏差从不超过 k 度。换言之,若第 i 天的实际气温为 c,则恒有 ∣ai−c∣≤k。
例如,设数组 a=[1,3,5,3,9],长度 n=5,且 k=2;另给定数组 b=[2,5,11,2,4]。那么,为使 bi 对应第 i 天的实际气温,我们可以将数组 b 重排为 [2,2,5,4,11]。验证如下:
- 第 1 天:∣a1−b1∣=∣1−2∣=1,满足 1≤2=k;
- 第 2 天:∣a2−b2∣=∣3−2∣=1,满足 1≤2=k;
- 第 3 天:∣a3−b3∣=∣5−5∣=0,满足 0≤2=k;
- 第 4 天:∣a4−b4∣=∣3−4∣=1,满足 1≤2=k;
- 第 5 天:∣a5−b5∣=∣9−11∣=2,满足 2≤2=k。
输入格式
The first line of input data contains a single integer t (1≤t≤104) — the number of test cases.
The description of the test cases follows.
The first line of each test case contains two integers n (1≤n≤105) and k (0≤k≤109) — 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 n integers — elements of array a (−109≤ai≤109).
The third line of each test case contains exactly n integers — elements of array b (−109≤bi≤109).
It is guaranteed that the sum of n over all test cases does not exceed 105, and that the elements of array b can always be rearranged so that the equality ∣ai−bi∣≤k is true for all i.
输入数据的第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
接下来是各测试用例的描述。
每个测试用例的第一行包含两个整数 n(1≤n≤105)和 k(0≤k≤109)—— 分别表示天数,以及每天预期气温与实际气温之间的最大允许差值。
每个测试用例的第二行包含恰好 n 个整数 —— 数组 a 的元素(−109≤ai≤109)。
每个测试用例的第三行包含恰好 n 个整数 —— 数组 b 的元素(−109≤bi≤109)。
保证所有测试用例的 n 值之和不超过 105,且数组 b 的元素总能被重新排列,使得对所有 i 均满足不等式 ∣ai−bi∣≤k。
输出格式
On a separate line for each test case, output exactly n 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.
对每个测试用例,在单独的一行中输出恰好 n 个数字——按正确顺序排列的每一天的气温值。
如果存在多个答案,则输出其中任意一个即可。
输入输出样例
输入#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测评打分。不知道怎么写?