CF1584C.Two Arrays
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
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?
给你两个整数数组 a1,a2,…,an 和 b1,b2,…,bn。
我们定义对数组 a 的一种变换如下:
- 选择任意一个非负整数 k,满足 0≤k≤n;
- 选择 k 个互不相同的数组下标 1≤i1<i2<…<ik≤n;
- 将 ai1,ai2,…,aik 各自加 1,数组 a 中其余元素保持不变;
- 以任意顺序重排数组 a 的所有元素。
是否可以恰好执行一次上述对数组 a 的变换,使得变换后的数组等于 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).
第一行包含一个整数 t(1≤t≤100)—— 表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 表示数组 a 和 b 的大小。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−100≤ai≤100)。
每个测试用例的第三行包含 n 个整数 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).
对于每个测试用例,如果可以对数组 a 执行某种变换,使得变换后的数组等于 b,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
你可以以任意大小写(大写或小写)输出每个字母。
输入输出样例
输入#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.
在第一个测试用例中,我们可以进行如下变换:
- 选择 k=2。
- 选择 i1=1,i2=2。
- 将 a1 和 a2 各加 1。得到的数组为 [0,2,0]。
- 交换第二位与第三位的元素。
在第二个测试用例中,不存在合适的变换。
在第三个测试用例中,我们选择 k=0,且不改变元素的顺序。
输入解题思路,AI测评打分。不知道怎么写?