310222: CF1798A. Showstopper

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Showstopper

题目描述

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 $ .

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #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.

Input

题意翻译

给你两个数组,每次操作可以交换两个数组对应位置的值,问经过若干次操作是否可以使这两个数组最后的值是这个数组最大的。

Output

**题目名称:Showstopper**

**题目描述:**
给定两个数组 $ a_1, a_2, \ldots, a_n $ 和 $ b_1, b_2, \ldots, b_n $。每次操作可以选择任意整数 $ i $(从 1 到 $ n $),并交换 $ a_i $ 和 $ b_i $ 的数值。判断是否可以通过任意次数(可能为零次)的操作,使得以下两个条件同时满足:
- $ a_n $ 等于 $ a_1, a_2, \ldots, a_n $ 中的最大值,
- $ b_n $ 等于 $ b_1, b_2, \ldots, b_n $ 中的最大值。

这里的 $ \max(c_1, c_2, \ldots, c_k) $ 表示 $ c_1, c_2, \ldots, c_k $ 中的最大数。例如,$ \max(3, 5, 4) = 5 $,$ \max(1, 7, 7) = 7 $,$ \max(6, 2) = 6 $。

**输入输出格式:**

**输入格式:**
每个测试包含多个测试案例。第一行包含测试案例的数量 $ t $($ 1 \le t \le 200 $)。接下来是每个测试案例的描述。
每个测试案例的第一行包含一个整数 $ n $($ 1 \le n \le 100 $)——数组长度。
第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $($ 1 \le a_i \le 100 $)——第一个数组的元素。
第三行包含 $ n $ 个整数 $ b_1, b_2, \ldots, b_n $($ 1 \le b_i \le 100 $)——第二个数组的元素。

**输出格式:**
对于每个测试案例,如果可以通过任意次数的操作满足上述条件,则打印 "Yes"。否则,打印 "No"。
答案可以用任何大小写输出,例如 "yEs"、"yes"、"Yes" 和 "YES" 都会被认为是肯定回答。

**输入输出样例:**

**输入样例 #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
```

**说明:**
- 在第一个测试案例中,可以交换 $ a_3 $ 和 $ b_3 $ 的数值,使得数组 $ a $ 变为 $ [7, 9, 9] $,数组 $ b $ 变为 $ [7, 6, 7] $,两个条件都满足。
- 在第二个测试案例中,可以证明不可能同时满足两个条件。
- 在第三个测试案例中,可以交换 $ a_1 $ 和 $ b_1 $ 的数值,使得数组 $ a $ 变为 $ [99, 99] $,数组 $ b $ 变为 $ [100, 100] $,两个条件都满足。
- 在第五个测试案例中,可以交换 $ a_7 $ 和 $ b_7 $,$ a_8 $ 和 $ b_8 $,$ a_9 $ 和 $ b_9 $ 的数值,使得数组 $ a $ 变为 $ [1, 2, 3, 4, 5, 6, 6, 6, 6] $,数组 $ b $ 变为 $ [9, 9, 9, 9, 9, 9, 7, 8, 9] $,两个条件都满足。**题目名称:Showstopper** **题目描述:** 给定两个数组 $ a_1, a_2, \ldots, a_n $ 和 $ b_1, b_2, \ldots, b_n $。每次操作可以选择任意整数 $ i $(从 1 到 $ n $),并交换 $ a_i $ 和 $ b_i $ 的数值。判断是否可以通过任意次数(可能为零次)的操作,使得以下两个条件同时满足: - $ a_n $ 等于 $ a_1, a_2, \ldots, a_n $ 中的最大值, - $ b_n $ 等于 $ b_1, b_2, \ldots, b_n $ 中的最大值。 这里的 $ \max(c_1, c_2, \ldots, c_k) $ 表示 $ c_1, c_2, \ldots, c_k $ 中的最大数。例如,$ \max(3, 5, 4) = 5 $,$ \max(1, 7, 7) = 7 $,$ \max(6, 2) = 6 $。 **输入输出格式:** **输入格式:** 每个测试包含多个测试案例。第一行包含测试案例的数量 $ t $($ 1 \le t \le 200 $)。接下来是每个测试案例的描述。 每个测试案例的第一行包含一个整数 $ n $($ 1 \le n \le 100 $)——数组长度。 第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $($ 1 \le a_i \le 100 $)——第一个数组的元素。 第三行包含 $ n $ 个整数 $ b_1, b_2, \ldots, b_n $($ 1 \le b_i \le 100 $)——第二个数组的元素。 **输出格式:** 对于每个测试案例,如果可以通过任意次数的操作满足上述条件,则打印 "Yes"。否则,打印 "No"。 答案可以用任何大小写输出,例如 "yEs"、"yes"、"Yes" 和 "YES" 都会被认为是肯定回答。 **输入输出样例:** **输入样例 #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 ``` **说明:** - 在第一个测试案例中,可以交换 $ a_3 $ 和 $ b_3 $ 的数值,使得数组 $ a $ 变为 $ [7, 9, 9] $,数组 $ b $ 变为 $ [7, 6, 7] $,两个条件都满足。 - 在第二个测试案例中,可以证明不可能同时满足两个条件。 - 在第三个测试案例中,可以交换 $ a_1 $ 和 $ b_1 $ 的数值,使得数组 $ a $ 变为 $ [99, 99] $,数组 $ b $ 变为 $ [100, 100] $,两个条件都满足。 - 在第五个测试案例中,可以交换 $ a_7 $ 和 $ b_7 $,$ a_8 $ 和 $ b_8 $,$ a_9 $ 和 $ b_9 $ 的数值,使得数组 $ a $ 变为 $ [1, 2, 3, 4, 5, 6, 6, 6, 6] $,数组 $ b $ 变为 $ [9, 9, 9, 9, 9, 9, 7, 8, 9] $,两个条件都满足。

加入题单

算法标签: