CF1584C.Two Arrays
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays of integers a1,a2,…,an and b1,b2,…,bn .
Let's define a transformation of the array a :
- Choose any non-negative integer k such that 0≤k≤n .
- Choose k distinct array indices 1≤i1<i2<…<ik≤n .
- Add 1 to each of ai1,ai2,…,aik , all other elements of array a remain unchanged.
- Permute the elements of array a in any order.
Is it possible to perform some transformation of the array a exactly once, so that the resulting array is equal to b ?
输入格式
The first line contains a single integer t ( 1≤t≤100 ) — the number of test cases. Descriptions of test cases follow.
The first line of each test case contains a single integer n ( 1≤n≤100 ) — the size of arrays a and b .
The second line of each test case contains n integers a1,a2,…,an ( −100≤ai≤100 ).
The third line of each test case contains n integers b1,b2,…,bn ( −100≤bi≤100 ).
输出格式
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array a , so that the resulting array is equal to b . 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=2 .
- Choose i1=1 , i2=2 .
- Add 1 to a1 and a2 . The resulting array is [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=0 and do not change the order of elements.