PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000077. Phá hủy các bức tường (Destroyer Takahashi)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phá hủy các bức tường (Destroyer Takahashi)
Destroyer Takahashi
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are walls on distinct rows of a grid with columns. Wall occupies columns through , inclusive. One punch affects every row in consecutive columns starting at an integer with . A wall is destroyed if at least one of its columns is hit. Find the minimum number of punches.
Input
The first line contains . Each of the following lines contains .
Output
Print the minimum number of punches.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3 3
1 2
4 7
5 9
Output
2
Explanation
A punch spanning columns – destroys the first two walls. A punch on columns – destroys the third. One punch cannot hit both the first and third walls, so two is optimal.