1896C.md (2382B)
1 Source: https://codeforces.com/problemset/problem/1896/C 2 3 C. Matching Arrays 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given two arrays $a$ and $b$ of size $n$. The beauty of the arrays $a$ and $b$ is the number of indices $i$ such that $a_i \gt b_i$. 22 23 You are also given an integer $x$. Determine whether it is possible to rearrange the elements of $b$ such that the beauty of the arrays becomes $x$. If it is possible, output one valid rearrangement of $b$. 24 25 Input 26 27 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 28 29 The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 2\cdot 10^5$, $0 \le x \le n$) — the size of arrays $a$ and $b$ and the desired beauty of the arrays. 30 31 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 2n$) — the elements of array $a$. 32 33 The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 2n$) — the elements of array $b$. 34 35 It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. 36 37 Output 38 39 For each test case, output "NO" if it is not possible to rearrange $b$ to make the beauty of the arrays equal to $x$. 40 41 Otherwise, output "YES". Then, on the next line, output $n$ integers which represent the rearrangement of $b$. 42 43 If there are multiple solutions, you may output any of them. 44 45 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. 46 47 Example 48 49 Input 50 51 ``` 52 7 53 54 1 0 55 56 1 57 58 2 59 60 1 1 61 62 1 63 64 2 65 66 3 0 67 68 2 4 3 69 70 4 1 2 71 72 3 1 73 74 2 4 3 75 76 4 1 2 77 78 3 2 79 80 2 4 3 81 82 4 1 2 83 84 3 3 85 86 2 4 3 87 88 4 1 2 89 90 5 2 91 92 6 4 5 6 2 93 94 9 7 9 1 1 95 ``` 96 97 Output 98 99 ``` 100 YES 101 2 102 NO 103 NO 104 YES 105 2 4 1 106 YES 107 4 1 2 108 NO 109 YES 110 1 9 9 7 1 111 ``` 112 113 Note 114 115 In test cases 1 and 2, the beauty of the arrays has to be $0$ since $a_1 = 1 \le 2 = b_1$. 116 117 In test cases 3, 4, 5 and 6, the only possible beauty of the arrays is $x = 1$ and $x = 2$. In particular, if $b$ is rearranged to $[2, 4, 1]$, then $a_3 = 3 \gt 1 = b_3$, so the beauty of the arrays is $1$. If $b$ is kept in the same order as given the input, then $a_2 = 4 \gt b_2 = 1$ and $a_3 = 3 \gt 2 = b_3$, so the beauty of the arrays is $2$.