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 C (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <stdio.h>
#include <stdlib.h>
#define n 100000000

void quicksort(int *A, int *B,int p, int r); /* 関数 quicksort の宣言 */
int partition(int *A, int *B,int p, int r); /* 関数 partition の宣言 */

int main(){
	int N, i,j,k; //ロボットの個数N
  	scanf("%d", &N);
  	int X[N], L[N]; 
  	int *y;
  	int count=0, loop=1, loop2=1; //取り除いた回数 count, loop=1
  
  	y = (int *)malloc(n * sizeof(int)); //メモリ
    
  
  	for(i=0; i++; i<N){
    	scanf("%d, %d", &X[i], L[i]);
    }
  	for(i=0; i++; i<n){
      y[i] = 0; //初期化
    }
  	
  	quicksort(X,L,0, N-1); /* quicksort を呼び出し */

  	
  	while(loop){
      	loop2++;
    	for(j=0;j++;j<N){
          while(loop2){
	          for(k=X[j]-L[j];k++;k<=X[j]+L[j]){
                if(k >= 0){
	    	      	if(y[k]==0){
    	    	    	y[k]++;
        	    	}
            		else{
                        //loop3--;
            			loop2--;
                  		j=N;
                  		X[k] =-1,L[k] = 0, count++; //ロボットの除去
               		}
          		  }	
              	}
            	if(loop2==1){
        			loop=0;
                  	loop2=0;
        		}
		      	else{
        	  		for(i=0; i++; i<n){
      				y[i] = 0; //初期
                    }
    			}
          	 }
        }      	
    }
  	
  	
  	printf("%d",N - count);
	return 0;
}

void quicksort(int *A, int *B, int p, int r){
    int q;

    if(p < r){
	q = partition(A, B,p, r);
	quicksort(A,B, p, q);
	quicksort(A,B, q+1, r);
    }
    
}

int partition(int *A, int *B,int p, int r){
    int x, i, j, tmp;
    x = A[p], i = p, j= r;
    
    while(i < j){
	while(x < A[j]){
	    j--;
	}
	while(x > A[i]){
	    i++;
	    }
	if(i < j){
	    tmp = A[j];
	    A[j] = A[i];
	    A[i] = tmp;
      	tmp = B[j];
	    B[j] = B[i];
	    B[i] = tmp;
	    i++;
	    j--;
	}
	if(i == j && A[j] > x){
	    j--;
	}
    }
    return j;
}