A15864 | Showstopper
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given two arrays $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$ .
In one operation, you can choose any integer $i$ from $1$ to $n$ and swap the numbers $a_i$ and $b_i$ .
Determine whether, after using any (possibly zero) number of operations, the following two conditions can be satisfied simultaneously:
- $a_n = \max(a_1, a_2, \ldots, a_n)$ ,
- $b_n = \max(b_1, b_2, \ldots, b_n)$ .
Here $\max(c_1, c_2, \ldots, c_k)$ denotes the maximum number among $c_1, c_2, \ldots, c_k$ . For example, $\max(3, 5, 4) = 5$ , $\max(1, 7, 7) = 7$ , $\max(6, 2) = 6$ .
In one operation, you can choose any integer $i$ from $1$ to $n$ and swap the numbers $a_i$ and $b_i$ .
Determine whether, after using any (possibly zero) number of operations, the following two conditions can be satisfied simultaneously:
- $a_n = \max(a_1, a_2, \ldots, a_n)$ ,
- $b_n = \max(b_1, b_2, \ldots, b_n)$ .
Here $\max(c_1, c_2, \ldots, c_k)$ denotes the maximum number among $c_1, c_2, \ldots, c_k$ . For example, $\max(3, 5, 4) = 5$ , $\max(1, 7, 7) = 7$ , $\max(6, 2) = 6$ .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 200$ ). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 100$ ) — the length of the arrays.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 100$ ) — elements of the first array.
The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ( $1 \le b_i \le 100$ ) — elements of the second array.
The first line of each test case contains a single integer $n$ ( $1 \le n \le 100$ ) — the length of the arrays.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 100$ ) — elements of the first array.
The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ( $1 \le b_i \le 100$ ) — elements of the second array.
输出格式
For each test case, print "Yes" if after using any (possibly zero) number of operations the conditions described above are satisfied. Otherwise, print "No".
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.
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.
输入输出样例
输入 #1
7 3 7 9 7 7 6 9 4 10 10 15 15 10 16 15 15 2 100 99 99 100 1 1 1 9 1 2 3 4 5 6 7 8 9 9 9 9 9 9 9 6 6 6 7 1 1 2 2 1 1 2 1 2 1 2 1 2 1 2 30 4 5 30
输出 #1
Yes No Yes Yes Yes No No
In the first test case, you can swap the numbers $a_3$ and $b_3$ , after which the array $a$ becomes equal to $[7, 9, 9]$ , and the array $b$ becomes equal to $[7, 6, 7]$ , and both conditions are met.
In the second test case, it can be proved that it is impossible to satisfy both conditions.
In the third test case, you can swap the numbers $a_1$ and $b_1$ , after which the array $a$ becomes equal to $[99, 99]$ , and the array $b$ becomes equal to $[100, 100]$ , and both conditions are satisfied.
In fifth test case, you can swap $a_7$ and $b_7$ , $a_8$ and $b_8$ , $a_9$ and $b_9$ , after which the array $a$ becomes equal to $[1, 2, 3, 4, 5, 6, 6, 6, 6]$ , and the array $b$ becomes equal to $[9, 9, 9, 9, 9, 9, 7, 8, 9]$ , and both conditions are satisfied.
In the second test case, it can be proved that it is impossible to satisfy both conditions.
In the third test case, you can swap the numbers $a_1$ and $b_1$ , after which the array $a$ becomes equal to $[99, 99]$ , and the array $b$ becomes equal to $[100, 100]$ , and both conditions are satisfied.
In fifth test case, you can swap $a_7$ and $b_7$ , $a_8$ and $b_8$ , $a_9$ and $b_9$ , after which the array $a$ becomes equal to $[1, 2, 3, 4, 5, 6, 6, 6, 6]$ , and the array $b$ becomes equal to $[9, 9, 9, 9, 9, 9, 7, 8, 9]$ , and both conditions are satisfied.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted