AtCoder Regular Contest 104
C
Fair Elevator
AtCoder
⌀ 2009
原题
← BD →
翻译中…

Problem Statement

翻译中…

There is a building with $2N$ floors, numbered $1, 2, \ldots, 2N$ from bottom to top.

翻译中…

The elevator in this building moved from Floor $1$ to Floor $2N$ just once.

翻译中…

On the way, $N$ persons got on and off the elevator. Each person $i$ $(1 \leq i \leq N)$ got on at Floor $A_i$ and off at Floor $B_i$. Here, $1 \leq A_i < B_i \leq 2N$, and just one person got on or off at each floor.

翻译中…

Additionally, because of their difficult personalities, the following condition was satisfied:

翻译中…
  • Let $C_i (= B_i - A_i - 1)$ be the number of times, while Person $i$ were on the elevator, other persons got on or off. Then, the following holds:
  • If there was a moment when both Person $i$ and Person $j$ were on the elevator, $C_i = C_j$.
翻译中…

We recorded the sequences $A$ and $B$, but unfortunately, we have lost some of the records. If the record of $A_i$ or $B_i$ is lost, it will be given to you as $-1$.

翻译中…

Additionally, the remaining records may be incorrect.

翻译中…

Determine whether there is a pair of $A$ and $B$ that is consistent with the remaining records.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 100$
  • $A_i = -1$ or $1 \leq A_i \leq 2N$.
  • $B_i = -1$ or $1 \leq B_i \leq 2N$.
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
A_2 B_2
:
A_N B_N

翻译中…

Output

翻译中…

If there is a pair of $A$ and $B$ that is consistent with the remaining records, print Yes; otherwise, print No.

翻译中…

样例

Input #1
3
1 -1
-1 4
-1 6
Output #1
Yes
For example, if $B_1 = 3, A_2 = 2$, and $A_3 = 5$, all the requirements are met. In this case, there is a moment when both Person $1$ and Person $2$ were on the elevator, which is fine since $C_1 = C_2 = 1$.
Input #2
2
1 4
2 3
Output #2
No
There is a moment when both Person $1$ and Person $2$ were on the elevator. Since $C_1 = 2, C_2 = 0$, some of the information is incorrect.
Input #3
2
4 1
2 4
Output #3
No
The records are seemingly intact but clearly are incorrect.
题目信息
题号
arc104_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。