PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000035. Trồng cây theo yêu cầu (Planting Trees)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trồng cây theo yêu cầu (Planting Trees)
Planting Trees
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
There are consecutive planting spots, at most one tree in each. Each resident requires at least planted trees among positions through . Intervals may overlap. Minimize the number of trees.
Input
The first line contains , the second line , followed by lines .
Output
Print the minimum number of trees.
Subtasks
- Subtask 1 (20 points): $1\le n\le40; 1\le h\le20; 1\le b_i\le e_i\le n; 1\le t_i\le e_i-b_i+1$.
- Subtask 2 (30 points): $1\le n\le3000; 1\le h\le800; 1\le b_i\le e_i\le n; 1\le t_i\le e_i-b_i+1$.
- Subtask 3 (50 points): $1\le n\le30000; 1\le h\le5000; 1\le b_i\le e_i\le n; 1\le t_i\le e_i-b_i+1$.
Examples
Input
5
2
1 3 2
3 5 2
Output
3
Explanation
Plant trees at positions . Each of the two resident intervals then has at least two trees. Because the intervals share only position , two trees cannot meet both demands.