CF1896C.Matching Arrays

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays aa and bb of size nn. The beauty of the arrays aa and bb is the number of indices ii such that ai>bia_i \gt b_i.

You are also given an integer xx. Determine whether it is possible to rearrange the elements of bb such that the beauty of the arrays becomes xx. If it is possible, output one valid rearrangement of bb.

给你两个长度为 nn 的数组 aa 和 bb。数组 aa 和 bb 的“美感”定义为满足 ai>bia_i \gt b_i 的下标 ii 的个数。

你还将得到一个整数 xx。请判断是否可以重新排列数组 bb 的元素,使得数组的“美感”恰好为 xx。如果可以,请输出数组 bb 的一种合法重排方案。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and xx (1≤n≤2⋅1051 \le n \le 2\cdot 10^5, 0≤x≤n0 \le x \le n) — the size of arrays aa and bb and the desired beauty of the arrays.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤2n1 \le a_i \le 2n) — the elements of array aa.

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤2n1 \le b_i \le 2n) — the elements of array bb.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 xx(1≤n≤2⋅1051 \le n \le 2\cdot 10^5,0≤x≤n0 \le x \le n)—— 分别表示数组 aa 和 bb 的大小,以及期望的数组“美观度”。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤2n1 \le a_i \le 2n)—— 表示数组 aa 的元素。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤2n1 \le b_i \le 2n)—— 表示数组 bb 的元素。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, output "NO" if it is not possible to rearrange bb to make the beauty of the arrays equal to xx.

Otherwise, output "YES". Then, on the next line, output nn integers which represent the rearrangement of bb.

If there are multiple solutions, you may output any of them.

You can output "YES" and "NO" in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

对于每个测试用例,如果无法重排数组 bb 使得两个数组的美观度等于 xx,则输出 "NO"。

否则,输出 "YES";然后在下一行输出 nn 个整数,表示数组 bb 的一种重排方案。

若存在多种可行解,输出任意一种即可。

"YES" 和 "NO" 的大小写不限(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为肯定回答)。

输入输出样例

  • 输入#1

    7
    1 0
    1
    2
    1 1
    1
    2
    3 0
    2 4 3
    4 1 2
    3 1
    2 4 3
    4 1 2
    3 2
    2 4 3
    4 1 2
    3 3
    2 4 3
    4 1 2
    5 2
    6 4 5 6 2
    9 7 9 1 1

    输出#1

    YES
    2
    NO
    NO
    YES
    2 4 1
    YES
    4 1 2
    NO
    YES
    1 9 9 7 1

说明/提示

In test cases 1 and 2, the beauty of the arrays has to be 00 since a1=1≤2=b1a_1 = 1 \le 2 = b_1.

In test cases 3, 4, 5 and 6, the only possible beauty of the arrays is x=1x = 1 and x=2x = 2. In particular, if bb is rearranged to [2,4,1][2, 4, 1], then a3=3>1=b3a_3 = 3 \gt 1 = b_3, so the beauty of the arrays is 11. If bb is kept in the same order as given the input, then a2=4>b2=1a_2 = 4 \gt b_2 = 1 and a3=3>2=b3a_3 = 3 \gt 2 = b_3, so the beauty of the arrays is 22.

在测试用例 1 和 2 中,由于 a1=1≤2=b1a_1 = 1 \le 2 = b_1,数组的“优美值”必须为 00。

在测试用例 3、4、5 和 6 中,数组可能的“优美值”仅有 x=1x = 1 和 x=2x = 2。具体而言,若将 bb 重排为 [2,4,1][2, 4, 1],则 a3=3>1=b3a_3 = 3 \gt 1 = b_3,因此数组的“优美值”为 11;若保持 bb 与输入中相同的顺序,则 a2=4>b2=1a_2 = 4 \gt b_2 = 1 且 a3=3>2=b3a_3 = 3 \gt 2 = b_3,因此数组的“优美值”为 22。

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

首页