#P11385. Robot Elimination Tournament
Robot Elimination Tournament
Robot Elimination Tournament
In the annual robot championship in Bajtocja, there are \( n \) robots with distinct strength and agility values. The \( i\)-th robot is described by two parameters \( s_i \) and \( z_i \) (with \(1 \le s_i, z_i \le n\)), where all \( s_i \) and all \( z_i \) are distinct.
The tournament consists of a series of one-on-one duels. In a duel between robot \( i \) and robot \( j \):
- If \( s_i > s_j \) or \( z_i > z_j \), then robot \( i \) eliminates robot \( j \).
- If \( s_i < s_j \) or \( z_i < z_j \), then robot \( j \) eliminates robot \( i \).
Note that it is possible for both robots to be eliminated in the same duel. A robot that is not eliminated can continue to compete in subsequent duels. The championship achieves the highest viewership when all robots have been eliminated. Your task is to determine whether it is possible to schedule a sequence of duels so that eventually all robots are eliminated.
Observation: In a duel between two robots with parameters \((s_i, z_i)\) and \((s_j, z_j)\), if one robot is superior in exactly one attribute and inferior in the other then both will eliminate each other (a double elimination duel). In contrast, if one robot is superior in both attributes then only the weaker robot is eliminated (a single elimination duel). To end with no survivors, the elimination process must remove all robots. A natural way to achieve this is to pair up the robots into duels that result in double eliminations. After sorting the robots by increasing \( s \) (since all \( s \) are different), if we can partition them into pairs \((r_{2k-1}, r_{2k})\) such that \( z_{2k-1} > z_{2k} \) holds for every pair, then each duel will eliminate both robots.
Thus, a necessary and sufficient condition for the complete elimination is that the number of robots \( n \) is even and, after sorting by \( s \), every pair of consecutive robots \( (r_{2k-1}, r_{2k}) \) satisfies \( z_{2k-1} > z_{2k} \).
inputFormat
The first line contains an integer \( n \) denoting the number of robots. Each of the following \( n \) lines contains two integers \( s_i \) and \( z_i \) representing the strength and agility of the \( i \)-th robot, respectively.
It is guaranteed that \(1 \leq s_i, z_i \leq n\) for all \( i \), and that all \( s_i \) (and all \( z_i \)) are distinct.
outputFormat
Output a single line containing YES
if it is possible to schedule the duels so that all robots are eliminated, and NO
otherwise.
sample
2
1 2
2 1
YES