#P8896. Acyclic Tournament Orientation

    ID: 22060 Type: Default 1000ms 256MiB

Acyclic Tournament Orientation

Acyclic Tournament Orientation

There are n strongholds on the battlefield numbered from 1 to n. Every pair of strongholds is connected by a bidirectional road. One day, the commander gets lost and orders you to reorient each road into a one-way road such that the resulting graph does not contain any cycle. In a complete graph like this, an acyclic orientation is a transitive tournament, meaning that if the strongholds are arranged in a certain order, each stronghold has directed roads only to those that come later in the order.

More precisely, if the strongholds are ordered in a permutation P then the outdegree (the number of directly reachable strongholds) of the stronghold at position j (i.e. P[j]) is n - j. However, because the sizes of the strongholds differ, the commander requires that the outdegree of stronghold i must lie in the interval \[ [l_i,\; r_i] \] which, given the ordering, is equivalent to requiring that the assigned position p of stronghold i satisfies \[ n - r_i \le p \le n - l_i. \]

Your task is to determine whether it is possible to assign each stronghold a distinct position from 1 to n (thus forming a permutation) such that all these conditions are met. If such an assignment exists, output YES; otherwise, output NO.

inputFormat

The first line contains an integer n (1 ≤ n ≤ 105), the number of strongholds.

The next n lines each contain two integers li and ri (0 ≤ liri ≤ n - 1) representing the required outdegree interval for stronghold i.

outputFormat

If a valid assignment of positions exists, output YES; otherwise, output NO.

sample

3
0 2
0 1
1 1
YES