传统题 1000ms 256MiB

Woodcutters

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题面翻译

nn 棵树在一维数轴上的坐标 xix_i,以及它们的长度 hih_i。现在要你砍倒这些树,树可以向左倒也可以向右倒,砍倒的树不能重合、当然也不能覆盖其他的树原来的位置,现在求最大可以砍倒的树的数目。

1n105 1 \le n \le {10}^5

1xi,hi109 1 \le x_i, h_i \le {10}^9

题目描述

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 n n trees located along the road at points with coordinates x1,x2,...,xn x_{1},x_{2},...,x_{n} . Each tree has its height hi h_{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 xi x_{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 n n ( 1<=n<=105 1<=n<=10^{5} ) — the number of trees.

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

The pairs are given in the order of ascending xi x_{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

样例输入 #1

5
1 2
2 1
5 10
10 9
19 1

样例输出 #1

3

样例 #2

样例输入 #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 1 1 -st tree to the left — now it occupies segment [1;1] [-1;1]
  • fell the 2 2 -nd tree to the right — now it occupies segment [2;3] [2;3]
  • leave the 3 3 -rd tree — it occupies point 5 5
  • leave the 4 4 -th tree — it occupies point 10 10
  • fell the 5 5 -th tree to the right — now it occupies segment [19;20] [19;20]

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

数据范围

对于40%40\%的数据,n10n\leq 10

对于80%80\%的数据,n104n\leq 10^4

对于100%100\%的数据,n105n\leq 10^5

12.8 城阳提高组动态规划

未参加
状态
已结束
规则
IOI
题目
9
开始于
2024-12-8 8:30
结束于
2024-12-8 11:36
持续时间
3.1 小时
主持人
参赛人数
10