2023-ho-t2_Advertisement_2 (JOI JOI)
Time limit: 2 seconds | Memory limit: 1024 MB | Task type: batch
Algorithms: data structures, greedy, sorting

![](_page_0_Picture_0.jpeg)

# 2 Advertisement 2

There are *N* residents in JOI Kingdom, numbered from 1 to *N*. Resident *i* (1 ≤ *i* ≤ *N*) lives at the coordinate *X<sub>i</sub>* on the real line, and its power of influence is *E<sub>i</sub>*. It may be the case that more than one resident lives at the same coordinate. A resident with a large power of influence has a high advertising potential, but such a resident is careful in buying books.

Rie published a book on informatics. In order to encourage many people to buy copies of the book, she can donate copies of the book to some residents. If she donates a copy of the book to Resident *i* (1 ≤ *i* ≤ *N*), Resident *i* will get a copy of Rie's book. Moreover, among the residents who did not yet get copies of the book, every resident *j* (1 ≤ *j* ≤ *N*) satisfying the following condition will buy a copy of the book and get it:

The distance between Resident *i* and Resident *j* on the real line is less than or equal to *E<sub>i</sub>* − *E<sub>j</sub>*. In other words, |*X<sub>i</sub>* − *X<sub>j</sub>*| ≤ *E<sub>i</sub>* − *E<sub>j</sub>* is satisfied.

If all the residents read Rie's book, the Olympiads in Informatics will be greatly recognized. Write a program which calculates the minimum number of residents who will be donated copies of Rie's book so that all the residents in JOI Kingdom will get copies of Rie's book.

## Input

Read the following data from the standard input:

```
N
X1 E1
X2 E2
:
XN EN
```

## Output

Write one line to the standard output. The output should contain the minimum number of residents who will be donated copies of Rie's book.

![](_page_1_Picture_0.jpeg)

## Constraints

*   1 ≤ *N* ≤ 500 000.
*   1 ≤ *X<sub>i</sub>* ≤ 10<sup>9</sup> (1 ≤ *i* ≤ *N*).
*   1 ≤ *E<sub>i</sub>* ≤ 10<sup>9</sup> (1 ≤ *i* ≤ *N*).
*   Given values are all integers.

## Subtasks

1.  (10 points) *E*<sub>1</sub> = *E*<sub>2</sub> = · · · = *E<sub>N</sub>*.
2.  (23 points) *N* ≤ 16.
3.  (36 points) *N* ≤ 1 000.
4.  (31 points) No additional constraints.

## Sample Input and Output

| Sample Input 1 | Sample Output 1 |
| :------------- | :-------------- |
| 4              | 2               |
| 4 2            |                 |
| 2 3            |                 |
| 3 4            |                 |
| 6 5            |                 |

For example, if Rie donates copies of the book in the following way, all the residents in JOI Kingdom will get copies of Rie's book.

*   Rie donates a copy of the book to Resident 3.
    *   Since |*X*<sub>3</sub> − *X*<sub>1</sub>| = 1 and *E*<sub>3</sub> − *E*<sub>1</sub> = 2, Resident 1 will buy a copy of Rie's book and get it.
    *   Since |*X*<sub>3</sub> − *X*<sub>2</sub>| = 1 and *E*<sub>3</sub> − *E*<sub>2</sub> = 1, Resident 2 will buy a copy of Rie's book and get it.
    *   Since |*X*<sub>3</sub> − *X*<sub>4</sub>| = 3 and *E*<sub>3</sub> − *E*<sub>4</sub> = −1, Resident 4 will not buy a copy of Rie's book.

    Therefore, Residents 1, 2, and 3 will get copies of Rie's book.

*   Rie donates a copy of the book to Resident 4. Since all the residents except Resident 4 already got copies of Rie's book, all the residents in JOI Kingdom finally get copies of Rie's book.

Since it is impossible to donate copies of the book to less than two residents so that all the residents in JOI Kingdom will get copies of Rie's book, output 2.

![](_page_2_Picture_0.jpeg)

This sample input satisfies the constraints of Subtasks 2, 3, and 4.

| Sample Input 2 | Sample Output 2 |
| :------------- | :-------------- |
| 3              | 2               |
| 7 10           |                 |
| 10 10          |                 |
| 7 10           |                 |

This sample input satisfies the constraints of all the subtasks.

| Sample Input 3      | Sample Output 3 |
| :------------------ | :-------------- |
| 10                  | 5               |
| 31447678 204745778  |                 |
| 430226982 292647686 |                 |
| 327782937 367372305 |                 |
| 843320852 822224390 |                 |
| 687565054 738216211 |                 |
| 970840050 766211141 |                 |
| 563662348 742939240 |                 |
| 103739645 854320982 |                 |
| 294864525 601612333 |                 |
| 375952316 469655019 |                 |

This sample input satisfies the constraints of Subtasks 2, 3, and 4.

Starter code:

Grader code:

Setup script:

Evaluation script: