Dominoes
View as PDFFarmer John's son, Johnny is playing with some dominoes one afternoon.
His dominoes come in a variety of heights and colors.
Just like any other child, he likes to put them in a row and knock them over.
He wants to know something: how many pushes does it take to knock down all the dominoes?
Johnny is lazy, so he wants to minimize the number of pushes he takes.
A domino, once knocked over, will knock over any domino that it touches on the way down.
For the sake of simplicity, imagine the floor as a one-dimensional line, where  is the leftmost point. Dominoes will not slip along the floor once toppled. Also, dominoes do have some width: a domino of length 
 at position 
 can knock over a domino at position 
.
For the mathematically minded:
A domino at position  with height 
, once pushed to the right, will knock all dominoes at positions 
 rightward as well.
Conversely, the same domino pushed to the left will knock all dominoes at positions  leftward.
Input Specification
The input starts with a single integer , the number of dominoes, followed by 
 pairs of integers.
Each pair of integers represents the  and 
 of a domino.
No two dominoes will be in the same location.
NOTE:  of test data has 
.
Output Specification
One line, with the number of pushes required.
Sample Input
6
1 1
2 2
3 1
5 1
6 1
8 3
Sample Output
2
Push the domino at location  rightward, the domino at location 
 leftward.
Diagram
              |
  |           |
| | |   | |   |
1 2 3 4 5 6 7 8
Pushing  causes 
 and 
 to fall, while pushing 
 causes 
 to fall and gently makes 
 tip over as well.
Comments