PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000060. Liên hoan phim (Movie Festival)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Liên hoan phim (Movie Festival)
Movie Festival
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
At a festival, movies have starting times and ending times . You want to watch as many entire movies as possible. You may watch another movie immediately when the previous one ends. Find the maximum number of movies you can watch in full.
Input
The first line contains . Each of the next lines contains integers , the start and end times of movie .
Output
Print one integer: the maximum number of movies that can be watched in full.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
3
3 5
4 9
5 8
Output
2
Explanation
The movies occupy , , and . Watch the first until time , then the third from to , for movies. All three cannot be watched without overlap.