Codeforces Round 303 (Div. 2)
C
Woodcutters
Codeforces
1500
原题
← BD →
翻译中…

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*$ trees located along the road at points with coordinates $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$. Each tree has its height $*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 $[*x*_{*i*} - *h*_{*i*}, *x*_{*i*}]$ or $[*x*_{*i*};*x*_{*i*} + *h*_{*i*}]$. The tree that is not cut down occupies a single point with coordinate $*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.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the number of trees.

翻译中…

Next $*n*$ lines contain pairs of integers $*x*_{*i*}, *h*_{*i*}$ ($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 $*x*_{*i*}$. No two trees are located at the point with the same coordinate.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…
  • fell the $1$-st tree to the left — now it occupies segment $[ - 1;1]$
  • fell the $2$-nd tree to the right — now it occupies segment $[2;3]$
  • leave the $3$-rd tree — it occupies point $5$
  • leave the $4$-th tree — it occupies point $10$
  • fell the $5$-th tree to the right — now it occupies segment $[19;20]$
翻译中…

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

翻译中…

样例

Input #1
5
1 2
2 1
5 10
10 9
19 1
Output #1
3
InputCopy OutputCopy
Input #2
5
1 2
2 1
5 10
10 9
20 1
Output #2
4
InputCopy OutputCopy
题目信息
题号
545C
时间限制
1 s
内存限制
256 MB
标签
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。