codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1927C.md (3193B)


      1 Source: https://codeforces.com/problemset/problem/1927/C
      2 
      3 C. Choose the Different Ones!
      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 Given an array $a$ of $n$ integers, an array $b$ of $m$ integers, and an even number $k$.
     22 
     23 Your task is to determine whether it is possible to choose exactly $\frac{k}{2}$ elements from both arrays in such a way that among the chosen elements, every integer from $1$ to $k$ is included.
     24 
     25 For example:
     26 
     27 * If $a=[2, 3, 8, 5, 6, 5]$, $b=[1, 3, 4, 10, 5]$, $k=6$, then it is possible to choose elements with values $2, 3, 6$ from array $a$ and elements with values $1, 4, 5$ from array $b$. In this case, all numbers from $1$ to $k=6$ will be included among the chosen elements.
     28 * If $a=[2, 3, 4, 5, 6, 5]$, $b=[1, 3, 8, 10, 3]$, $k=6$, then it is not possible to choose elements in the required way.
     29 
     30 Note that you are not required to find a way to choose the elements — your program should only check whether it is possible to choose the elements in the required way.
     31 
     32 Input
     33 
     34 The first line of the input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The descriptions of the test cases follow.
     35 
     36 The first line of each test case contains three integers $n$, $m$, and $k$ ($1 \le n, m \le 2\cdot10^5$, $2 \le k \le 2 \cdot \min(n, m)$, $k$ is even) — the length of array $a$, the length of array $b$, and the number of elements to be chosen, respectively.
     37 
     38 The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — the elements of array $a$.
     39 
     40 The third line of each test case contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_j \le 10^6$) — the elements of array $b$.
     41 
     42 It is guaranteed that the sum of values $n$ and $m$ over all test cases in a test does not exceed $4 \cdot 10^5$.
     43 
     44 Output
     45 
     46 Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output "YES" if it is possible to choose $\frac{k}{2}$ numbers from each array in such a way that among the chosen elements, every integer from $1$ to $k$ is included. Otherwise, output "NO".
     47 
     48 You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
     49 
     50 Example
     51 
     52 Input
     53 
     54 ```
     55 6
     56 
     57 6 5 6
     58 
     59 2 3 8 5 6 5
     60 
     61 1 3 4 10 5
     62 
     63 6 5 6
     64 
     65 2 3 4 5 6 5
     66 
     67 1 3 8 10 3
     68 
     69 3 3 4
     70 
     71 1 3 5
     72 
     73 2 4 6
     74 
     75 2 5 4
     76 
     77 1 4
     78 
     79 7 3 4 4 2
     80 
     81 1 4 2
     82 
     83 2
     84 
     85 6 4 4 2
     86 
     87 1 5 2
     88 
     89 3
     90 
     91 2 2 1 4 3
     92 ```
     93 
     94 Output
     95 
     96 ```
     97 YES
     98 NO
     99 YES
    100 YES
    101 NO
    102 NO
    103 ```
    104 
    105 Note
    106 
    107 In the first test case of the example, it is possible to choose elements equal to $2$, $3$, and $6$ from array $a$ and elements equal to $1$, $4$, and $5$ from array $b$. Thus, all numbers from $1$ to $k=6$ are included among the chosen elements.
    108 
    109 In the second test case of the example, it can be shown that it is not possible to choose exactly three elements from each array in the required way.
    110 
    111 In the third test case of the example, it is possible to choose elements equal to $1$ and $3$ from array $a$ and elements equal to $2$ and $4$ from array $b$. Thus, all numbers from $1$ to $k=4$ are included among the chosen elements.