Under construction

Still being built. Things may change

Dominoes (Large)

Time limit1sMemory limit512 MB

Summary
Find the fewest pushes (each a domino plus a direction) needed to topple every domino through chain reactions.
Level

Hard8 of 10

Topics
Greedy, Sorting, Dynamic programming, Intervals
Solved
No attempts yet

Problem

NN dominoes stand on a number line. Domino ii stands at position XiX_i with height HiH_i, and no two dominoes share a position.

You may pick one domino and push it to the left or to the right. Pushing a domino at position xx with height hh to the left makes every domino at a position pp with x−h≤p≤xx - h \le p \le x fall to the left. Pushing it to the right makes every domino at a position pp with x≤p≤x+hx \le p \le x + h fall to the right. A domino that falls this way keeps falling in the same direction and knocks over the dominoes inside its own range. The chain continues until no new domino falls.

Each push picks one domino and one direction. Compute the minimum number of pushes that knocks over all NN dominoes.

Input

The first line contains NN. (1≤N≤500 0001 \le N \le 500\,000)

Each of the next NN lines contains two integers XiX_i and HiH_i, the position and the height of one domino, separated by a space. (1≤Xi,Hi≤2 000 000 0001 \le X_i, H_i \le 2\,000\,000\,000)

The dominoes are not necessarily given in order of position.

Output

Print the minimum number of pushes that knocks over every domino on the first line.

Examples1

  1. Example 1

    Input
    5
    1 2
    3 1
    6 2
    7 1
    9 2
    
    Expected output
    2