codeforces-scrape

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

2131C.md (2083B)


      1 Source: https://codeforces.com/problemset/problem/2131/C
      2 
      3 C. Make it Equal
      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 two [multisets](https://en.wikipedia.org/wiki/Multiset) $S$ and $T$ of size $n$ and a positive integer $k$, you may perform the following operations any number (including zero) of times on $S$:
     22 
     23 * Select an element $x$ in $S$, and remove one occurrence of $x$ in $S$. Then, either insert $x+k$ into $S$, or insert $|x-k|$ into $S$.
     24 
     25 Determine if it is possible to make $S$ equal to $T$. Two multisets $S$ and $T$ are equal if every element appears the same number of times in $S$ and $T$.
     26 
     27 Input
     28 
     29 Each test contains multiple test cases. The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
     30 
     31 The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $ 1 \le k \le 10^9$) — the size of $S$ and the constant, respectively.
     32 
     33 The second line contains $n$ integers $S_1,S_2,\ldots,S_n$ ($0 \le S_i \le 10^9$) — the elements in $S$.
     34 
     35 The third line contains $n$ integers $T_1,T_2,\ldots,T_n$ ($0 \le T_i \le 10^9$) — the elements in $T$.
     36 
     37 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 For each test case, output "YES" if it is possible to make $S$ equal to $T$, and "NO" otherwise.
     42 
     43 You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 5
     51 
     52 1 3
     53 
     54 1
     55 
     56 2
     57 
     58 1 8
     59 
     60 4
     61 
     62 12
     63 
     64 3 5
     65 
     66 6 2 9
     67 
     68 8 4 11
     69 
     70 2 7
     71 
     72 2 8
     73 
     74 2 9
     75 
     76 3 2
     77 
     78 0 1 0
     79 
     80 1 0 1
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 YES
     87 YES
     88 YES
     89 NO
     90 NO
     91 ```
     92 
     93 Note
     94 
     95 In the first test case, we can remove one occurrence of $1$ from $S$ and insert $|1-k|=|1-3|=2$ into $S$, making $S$ equal to $T$.
     96 
     97 In the second test case, we can remove one occurrence of $4$ from $S$ and insert $4+k=4+8=12$ into $S$, making $S$ equal to $T$.
     98 
     99 In the last test case, we can show that it is impossible to make $S$ equal to $T$.