PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000087. Những người đốn gỗ (Woodcutters)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Những người đốn gỗ (Woodcutters)
Woodcutters
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are trees at strictly increasing coordinates , with heights . Each tree may remain standing at or be felled left to occupy , or right to occupy . No fallen tree may overlap the occupied position or interval of another tree, including touching endpoints. Maximize the number of felled trees.
Input
The first line contains . Each of the next lines contains in strictly increasing order.
Output
Print the maximum number of trees that can be felled.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5
1 2
2 1
5 2
10 9
19 1
Output
4
Explanation
Fell the tree at left, at right, at right and at right; leave the tree at standing. Four trees can be felled, and the greedy process shows this is maximal.