Woodcutters
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题面翻译
给 棵树在一维数轴上的坐标 ,以及它们的长度 。现在要你砍倒这些树,树可以向左倒也可以向右倒,砍倒的树不能重合、当然也不能覆盖其他的树原来的位置,现在求最大可以砍倒的树的数目。
题目描述
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 trees located along the road at points with coordinates . Each tree has its height . Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments or . The tree that is not cut down occupies a single point with coordinate . 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 ( ) — the number of trees.
Next lines contain pairs of integers ( ) — the coordinate and the height of the -th tree.
The pairs are given in the order of ascending . 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 -st tree to the left — now it occupies segment
- fell the -nd tree to the right — now it occupies segment
- leave the -rd tree — it occupies point
- leave the -th tree — it occupies point
- fell the -th tree to the right — now it occupies segment
In the second sample you can also fell -th tree to the right, after that it will occupy segment .
数据范围
对于的数据,
对于的数据,
对于的数据,