CF1584C.Two Arrays

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given two arrays of integers a1,a2,,ana_1, a_2, \ldots, a_n and b1,b2,,bnb_1, b_2, \ldots, b_n .

Let's define a transformation of the array aa :

  1. Choose any non-negative integer kk such that 0kn0 \le k \le n .
  2. Choose kk distinct array indices 1i1<i2<<ikn1 \le i_1 < i_2 < \ldots < i_k \le n .
  3. Add 11 to each of ai1,ai2,,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} , all other elements of array aa remain unchanged.
  4. Permute the elements of array aa in any order.

Is it possible to perform some transformation of the array aa exactly once, so that the resulting array is equal to bb ?

输入格式

The first line contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. Descriptions of test cases follow.

The first line of each test case contains a single integer nn ( 1n1001 \le n \le 100 ) — the size of arrays aa and bb .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 100ai100-100 \le a_i \le 100 ).

The third line of each test case contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n ( 100bi100-100 \le b_i \le 100 ).

输出格式

For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array aa , so that the resulting array is equal to bb . Print "NO" (without quotes) otherwise.

You can print each letter in any case (upper or lower).

输入输出样例

  • 输入#1

    3
    3
    -1 1 0
    0 0 2
    1
    0
    2
    5
    1 2 3 4 5
    1 2 3 4 5

    输出#1

    YES
    NO
    YES

说明/提示

In the first test case, we can make the following transformation:

  • Choose k=2k = 2 .
  • Choose i1=1i_1 = 1 , i2=2i_2 = 2 .
  • Add 11 to a1a_1 and a2a_2 . The resulting array is [0,2,0][0, 2, 0] .
  • Swap the elements on the second and third positions.

In the second test case there is no suitable transformation.

In the third test case we choose k=0k = 0 and do not change the order of elements.

首页