#CT0000147. Lịch sử dụng phòng (Room Scheduling)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Lịch sử dụng phòng (Room Scheduling)
Room Scheduling
Version: Phuoc Hung OJ Extended
Problem Statement

A school has one computer room and receives requests to use it. Request uses the room from time until , where .
Each interval is half-open : the room becomes occupied at and is released at . Therefore a session may start at exactly the time when another ends.
The school may accept or reject each request, but no two accepted sessions may occupy the room at the same instant.
Find the maximum number of requests that can be accepted.
Input
The first line contains a positive integer .
Each of the next lines contains two integers and , the starting and ending times of request , respectively.
Output
Print one integer: the maximum number of requests that can be accepted without overlapping sessions.
Subtasks
- Subtask 1 (30 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (40 points): ; for every .
Examples
Example 1
Input
5
1 3
2 5
3 4
4 7
6 8
Output
3
Explanation
Accept , , and . Their endpoints meet without overlap. The other two intervals overlap the selected schedule; a schedule with four sessions is impossible for these five requests. The answer is .
Example 2
Input
4
1 10
2 3
3 4
4 5
Output
3
Explanation
Accepting prevents all other requests. Reject it and accept , , and instead, obtaining sessions. These are all three remaining requests, so no better schedule exists.
Example 3
Input
3
1 2
2 3
3 4
Output
3
Explanation
The intervals , , and run consecutively. An ending time may equal the next starting time, so all requests can be accepted.
Liên quan
Trong các cuộc thi sau: