CF545C.Woodcutters

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.

There are nn trees located along the road at points with coordinates x1,x2,...,xnx_{1},x_{2},...,x_{n} . Each tree has its height hih_{i} . Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xihi,xi][x_{i}-h_{i},x_{i}] or [xi;xi+hi][x_{i};x_{i}+h_{i}] . The tree that is not cut down occupies a single point with coordinate xix_{i} . Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.

输入格式

The first line contains integer nn ( 1<=n<=1051<=n<=10^{5} ) — the number of trees.

Next nn lines contain pairs of integers xi,hix_{i},h_{i} ( 1<=xi,hi<=1091<=x_{i},h_{i}<=10^{9} ) — the coordinate and the height of the іі -th tree.

The pairs are given in the order of ascending xix_{i} . No two trees are located at the point with the same coordinate.

输出格式

Print a single number — the maximum number of trees that you can cut down by the given rules.

输入输出样例

  • 输入#1

    5
    1 2
    2 1
    5 10
    10 9
    19 1
    

    输出#1

    3
    
  • 输入#2

    5
    1 2
    2 1
    5 10
    10 9
    20 1
    

    输出#2

    4
    

说明/提示

In the first sample you can fell the trees like that:

  • fell the 11 -st tree to the left — now it occupies segment [1;1][-1;1]
  • fell the 22 -nd tree to the right — now it occupies segment [2;3][2;3]
  • leave the 33 -rd tree — it occupies point 55
  • leave the 44 -th tree — it occupies point 1010
  • fell the 55 -th tree to the right — now it occupies segment [19;20][19;20]

In the second sample you can also fell 44 -th tree to the right, after that it will occupy segment [10;19][10;19] .

首页