A14640 | Two Arrays
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given two arrays of integers $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$ .
Let's define a transformation of the array $a$ :
1. Choose any non-negative integer $k$ such that $0 \le k \le n$ .
2. Choose $k$ distinct array indices $1 \le i_1 < i_2 < \ldots < i_k \le n$ .
3. Add $1$ to each of $a_{i_1}, a_{i_2}, \ldots, a_{i_k}$ , all other elements of array $a$ remain unchanged.
4. 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$ ?
Let's define a transformation of the array $a$ :
1. Choose any non-negative integer $k$ such that $0 \le k \le n$ .
2. Choose $k$ distinct array indices $1 \le i_1 < i_2 < \ldots < i_k \le n$ .
3. Add $1$ to each of $a_{i_1}, a_{i_2}, \ldots, a_{i_k}$ , all other elements of array $a$ remain unchanged.
4. 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 \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 $n$ ( $1 \le n \le 100$ ) — the size of arrays $a$ and $b$ .
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-100 \le a_i \le 100$ ).
The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ( $-100 \le b_i \le 100$ ).
The first line of each test case contains a single integer $n$ ( $1 \le n \le 100$ ) — the size of arrays $a$ and $b$ .
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-100 \le a_i \le 100$ ).
The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ( $-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 $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).
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 $i_1 = 1$ , $i_2 = 2$ .
- Add $1$ to $a_1$ and $a_2$ . 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.
- Choose $k = 2$ .
- Choose $i_1 = 1$ , $i_2 = 2$ .
- Add $1$ to $a_1$ and $a_2$ . 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted