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 <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  scanf("%s", buf);

  return buf;
}

typedef struct _tmp_t {
  int64    a;  // covered points lo
  int64    b;  // covered points hi
  int64    x;
  int64    l;
  int      valid;
  int      ok;
} tmp_t;

tmp_t *get_NSeq (int64 n)
{
  tmp_t *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(tmp_t)));
  for (i=0; i<n; i++) {
    get_NK(&buf[i].x, &buf[i].l);
    buf[i].a = 0;
    buf[i].b = 0;
    buf[i].valid = 1;
  }
  return buf;
}


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->x > y->x) return 1;
  if (x->x < y->x) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

int compare_ab(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if ((x->a + x->b) > (y->a + y->b)) return -1;
  if ((x->a + x->b) < (y->a + y->b)) return 1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}
void qsort_ab (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_ab);
}

int64 check_range(tmp_t *r, int64 n)
{
  int64 i,j;
  int64 lo,hi;
  int64 max_index = 0;
  int64 max_cnt = 0;

//  printf("check_start\n");

  for (i=0; i<n; i++) {
    if (r[i].valid == 0) continue;
    if (r[i].ok) continue;
    r[i].a = 0;
    r[i].b = 0;
    lo = r[i].x - r[i].l;
    hi = r[i].x + r[i].l;
    if (i==0) lo = 0;
    if (i==(n-1)) hi=0;
    if (lo > 0) {
      for (j=(i-1); j>=0; j--) {
        if (r[j].valid == 0) continue;
        if ((r[j].x + r[j].l) > lo) {
          r[i].a++;
        } else {
          break;
        }
      }
    }
    if (hi > 0) {
      for (j=i+1; j<n; j++) {
        if (r[j].valid == 0) continue;
        if ((r[j].x - r[j].l) < hi) {
          r[i].b++;
        } else {
          break;
        }
      }
    }
    if ((r[i].a + r[i].b) == 0) {
      r[i].ok = 1;
      continue;
    }
//    printf("i=%d cnt=%d\n", i, (r[i].a + r[i].b));
    max_cnt = MAX((r[i].a + r[i].b), max_cnt);
    if (max_cnt == (r[i].a + r[i].b)) {
      max_index = i;
    }
  }// for i

//  printf("max_cnt=%d max_index=%d\n", max_cnt, max_index);
  if (max_cnt == 0) return -1;
  return max_index;
}

int main()
{
  int64 N, i;
  tmp_t *r;
  int64 result;
  int64 max_index;

  get_N(&N);
  result = N;

  r = get_NSeq(N);
  qsort_a(r, N);

retry:
  max_index = check_range(r, N);
  if (max_index >= 0) {
    r[max_index].valid = 0;
    result--;
    goto retry;
  }
   
  printf("%lld", result);

  return 0;
}
//             111
//   0123456789012
//   --2----
//    ---4---
//         ---9---