103551: [Atcoder]ABC355 B - Piano 2

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

Description

Score : $200$ points

Problem Statement

You are given a sequence $A=(A_1,A_2,\dots,A_N)$ of length $N$ and a sequence $B=(B_1,B_2,\dots,B_M)$ of length $M$. Here, all elements of $A$ and $B$ are pairwise distinct. Determine whether the sequence $C=(C_1,C_2,\dots,C_{N+M})$ formed by sorting all elements of $A$ and $B$ in ascending order contains two consecutive elements appearing in $A$.

Constraints

  • $1 \leq N, M \leq 100$
  • $1 \leq A_i, B_j \leq 200$
  • $A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M$ are distinct.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
$B_1$ $B_2$ $\dots$ $B_M$

Output

If $C$ contains two consecutive elements appearing in $A$, print Yes; otherwise, print No.


Sample Input 1

3 2
3 2 5
4 1

Sample Output 1

Yes

$C=(1,2,3,4,5)$. Since $2$ and $3$ from $A$ occur consecutively in $C$, print Yes.


Sample Input 2

3 2
3 1 5
4 2

Sample Output 2

No

$C=(1,2,3,4,5)$. Since no two elements from $A$ occur consecutively in $C$, print No.


Sample Input 3

1 1
1
2

Sample Output 3

No

Output

分数:200分

问题描述

给你一个长度为 $N$ 的序列 $A=(A_1,A_2,\dots,A_N)$ 和一个长度为 $M$ 的序列 $B=(B_1,B_2,\dots,B_M)$。其中,$A$ 和 $B$ 中的所有元素两两不同。判断由 $A$ 和 $B$ 中所有元素按升序排序后组成的序列 $C=(C_1,C_2,\dots,C_{N+M})$ 是否包含两个连续出现的 $A$ 中的元素。

限制条件

  • $1 \leq N, M \leq 100$
  • $1 \leq A_i, B_j \leq 200$
  • $A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M$ 都是不同的。
  • 所有输入值都是整数。

输入

输入从标准输入按以下格式给出:

$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
$B_1$ $B_2$ $\dots$ $B_M$

输出

如果 $C$ 中包含两个连续出现的 $A$ 中的元素,打印 Yes;否则,打印 No


样例输入 1

3 2
3 2 5
4 1

样例输出 1

Yes

$C=(1,2,3,4,5)$。因为 $A$ 中的 $2$ 和 $3$ 在 $C$ 中连续出现,所以打印 Yes


样例输入 2

3 2
3 1 5
4 2

样例输出 2

No

$C=(1,2,3,4,5)$。因为没有任何两个 $A$ 中的元素在 $C$ 中连续出现,所以打印 No


样例输入 3

1 1
1
2

样例输出 3

No

加入题单

算法标签: