atcoder#ARC104C. [ARC104C] Fair Elevator
[ARC104C] Fair Elevator
Score : points
Problem Statement
There is a building with floors, numbered from bottom to top.
The elevator in this building moved from Floor to Floor just once.
On the way, persons got on and off the elevator. Each person got on at Floor and off at Floor . Here, , and just one person got on or off at each floor.
Additionally, because of their difficult personalities, the following condition was satisfied:
- Let be the number of times, while Person were on the elevator, other persons got on or off. Then, the following holds:- If there was a moment when both Person and Person were on the elevator, .
- If there was a moment when both Person and Person were on the elevator, .
We recorded the sequences and , but unfortunately, we have lost some of the records. If the record of or is lost, it will be given to you as .
Additionally, the remaining records may be incorrect.
Determine whether there is a pair of and that is consistent with the remaining records.
Constraints
- or .
- or .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If there is a pair of and that is consistent with the remaining records, print Yes
; otherwise, print No
.
3
1 -1
-1 4
-1 6
Yes
For example, if , and , all the requirements are met.
In this case, there is a moment when both Person and Person were on the elevator, which is fine since .
2
1 4
2 3
No
There is a moment when both Person and Person were on the elevator. Since , some of the information is incorrect.
2
4 1
2 4
No
The records are seemingly intact but clearly are incorrect.