CF1798A.Showstopper

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two arrays a1,a2,…,ana_1, a_2, \ldots, a_n and b1,b2,…,bnb_1, b_2, \ldots, b_n.

In one operation, you can choose any integer ii from 11 to nn and swap the numbers aia_i and bib_i.

Determine whether, after using any (possibly zero) number of operations, the following two conditions can be satisfied simultaneously:

  • an=max⁡(a1,a2,…,an)a_n = \max(a_1, a_2, \ldots, a_n),
  • bn=max⁡(b1,b2,…,bn)b_n = \max(b_1, b_2, \ldots, b_n).

Here max⁡(c1,c2,…,ck)\max(c_1, c_2, \ldots, c_k) denotes the maximum number among c1,c2,…,ckc_1, c_2, \ldots, c_k. For example, max⁡(3,5,4)=5\max(3, 5, 4) = 5, max⁡(1,7,7)=7\max(1, 7, 7) = 7, max⁡(6,2)=6\max(6, 2) = 6.

给你两个数组 a1,a2,…,ana_1, a_2, \ldots, a_n 和 b1,b2,…,bnb_1, b_2, \ldots, b_n。

在一次操作中,你可以任选一个整数 ii(1≤i≤n1 \le i \le n),并交换 aia_i 与 bib_i 的值。

判断是否可以通过任意次(包括零次)操作,使得以下两个条件同时成立:

  • an=max⁡(a1,a2,…,an)a_n = \max(a_1, a_2, \ldots, a_n),
  • bn=max⁡(b1,b2,…,bn)b_n = \max(b_1, b_2, \ldots, b_n)。

其中 max⁡(c1,c2,…,ck)\max(c_1, c_2, \ldots, c_k) 表示 c1,c2,…,ckc_1, c_2, \ldots, c_k 中的最大值。例如:max⁡(3,5,4)=5\max(3, 5, 4) = 5,max⁡(1,7,7)=7\max(1, 7, 7) = 7,max⁡(6,2)=6\max(6, 2) = 6。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2001 \le t \le 200). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the length of the arrays.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1001 \le a_i \le 100) — elements of the first array.

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1001 \le b_i \le 100) — elements of the second array.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2001 \le t \le 200)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \le a_i \le 100)—— 第一个数组的元素。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1001 \le b_i \le 100)—— 第二个数组的元素。

输出格式

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.

对于每个测试用例,如果在执行任意次数(可能为零次)的操作后,上述条件均被满足,则输出“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

说明/提示

In the first test case, you can swap the numbers a3a_3 and b3b_3, after which the array aa becomes equal to [7,9,9][7, 9, 9], and the array bb becomes equal to [7,6,7][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 a1a_1 and b1b_1, after which the array aa becomes equal to [99,99][99, 99], and the array bb becomes equal to [100,100][100, 100], and both conditions are satisfied.

In fifth test case, you can swap a7a_7 and b7b_7, a8a_8 and b8b_8, a9a_9 and b9b_9, after which the array aa becomes equal to [1,2,3,4,5,6,6,6,6][1, 2, 3, 4, 5, 6, 6, 6, 6], and the array bb becomes equal to [9,9,9,9,9,9,7,8,9][9, 9, 9, 9, 9, 9, 7, 8, 9], and both conditions are satisfied.

在第一个测试用例中,你可以交换数字 a3a_3 和 b3b_3,之后数组 aa 变为 [7,9,9][7, 9, 9],数组 bb 变为 [7,6,7][7, 6, 7],且两个条件均被满足。

在第二个测试用例中,可以证明无法同时满足两个条件。

在第三个测试用例中,你可以交换数字 a1a_1 和 b1b_1,之后数组 aa 变为 [99,99][99, 99],数组 bb 变为 [100,100][100, 100],且两个条件均被满足。

在第五个测试用例中,你可以交换 a7a_7 和 b7b_7、a8a_8 和 b8b_8、a9a_9 和 b9b_9,之后数组 aa 变为 [1,2,3,4,5,6,6,6,6][1, 2, 3, 4, 5, 6, 6, 6, 6],数组 bb 变为 [9,9,9,9,9,9,7,8,9][9, 9, 9, 9, 9, 9, 7, 8, 9],且两个条件均被满足。

输入解题思路,AI测评打分。不知道怎么写?

首页