ARC104C - Fair Elevator
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Score : 600 points
Problem Statement
There is a building with 2N floors, numbered 1,2,…,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≤i≤N) got on at Floor Ai and off at Floor Bi. Here, 1≤Ai<Bi≤2N, and just one person got on or off at each floor.
Additionally, because of their difficult personalities, the following condition was satisfied:
- Let Ci(=Bi−Ai−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, Ci=Cj.
We recorded the sequences A and B, but unfortunately, we have lost some of the records. If the record of Ai or Bi 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≤N≤100
- Ai=−1 or 1≤Ai≤2N.
- Bi=−1 or 1≤Bi≤2N.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A1 B1 A2 B2 : AN BN
Output
If there is a pair of A and B that is consistent with the remaining records, print Yes
; otherwise, print No
.
Sample Input 1
3 1 -1 -1 4 -1 6
Sample Output 1
Yes
For example, if B1=3,A2=2, and A3=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 C1=C2=1.
Sample Input 2
2 1 4 2 3
Sample Output 2
No
There is a moment when both Person 1 and Person 2 were on the elevator. Since C1=2,C2=0, some of the information is incorrect.
Sample Input 3
2 4 1 2 4
Sample Output 3
No
The records are seemingly intact but clearly are incorrect.
ARC104
- Status
- Done
- Rule
- IOI
- Problem
- 5
- Start at
- 2023-6-30 8:15
- End at
- 2023-6-30 10:15
- Duration
- 2 hour(s)
- Host
- Partic.
- 14