Problem:
Score : 200 points

Problem Statement

In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.

We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

0 \leq X_i \leq 10^9 (1 \leq i \leq N)

1 \leq L_i \leq 10^9 (1 \leq i \leq N)

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

By removing Robot 2, we can keep the other three robots.

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5

Solution in Scala (2.11.7) (judge verdict: Wrong Answer)

object Main extends App{
    def readLine() = io.StdIn.readLine()
    
    val n = readLine().toInt
    val robots = Iterator.continually(readLine()).take(n).map(_.split(' ').map(_.toLong)).toArray.sortBy(_(0)).map {
        case Array(x, l) => Array(x - l, x + l)
    }.toArray
    
    def interference(robots: Array[Array[Long]], index: Int) = {
        val Array(left, right, _*) = robots(index)
        
        def findLeft(leftIndex: Int): Int = if (leftIndex == -1)
            0
        else if (robots(leftIndex)(1) <= left)
            leftIndex + 1
        else
            findLeft(leftIndex - 1)
        
        def findRight(rightIndex: Int): Int = if (rightIndex == robots.length)
            robots.length - 1
        else if (robots(rightIndex)(0) >= right)
            rightIndex - 1
        else
            findRight(rightIndex + 1)
        
        findRight(index) - findLeft(index)
    }
    
    def removeRobots(robots: Array[Array[Long]]): Array[Array[Long]] = if (robots.forall(_(2) == 0))
        robots
    else {
        robots.find(_(2) == 1) match {
            case Some(elem) =>
                val next = robots.filter(_ != elem)
                val recalc = (0 until next.length).map { i =>
                    val r = next(i)
                    if (r(2) == 0)
                        r
                    else
                        Array(r(0), r(1), interference(next, i))
                }.toArray
                removeRobots(recalc)
            case _ => throw new Exception("想定外")
        }
    }
    
    val filtered = (0 until n).map { i =>
        val r = robots(i)
        val in = interference(robots, i)
        Array(r(0), r(1), in)
    }.filter(_(2) <= 1).toArray
    
    val recalc = (0 until filtered.length).map { i =>
        val r = filtered(i)
        if (r(2) == 0)
            r
        else
            Array(r(0), r(1), interference(filtered, i))
    }.toArray
    
    val answer = removeRobots(recalc)
    
    println(answer.length)
}