#CT0000128. Dòng xe vào bến (Bus Station Queue)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Dòng xe vào bến (Bus Station Queue)
Bus Station Queue
Source: Bộ Giáo dục và Đào tạo
Version: Phuoc Hung OJ Extended
Problem Statement
Bus station XYZ has parking bays numbered through . There are buses arriving in the fixed order . Bus accepts only a bay whose index belongs to the interval . Each bay may serve at most one bus from this queue.
If the next bus cannot be assigned an acceptable unused bay, that bus and all later buses leave the station immediately. It is not permitted to skip a bus and serve subsequent ones.
Find the maximum number of consecutive buses from the beginning of the queue that can be served when the station may choose their assigned bays.
Input
- The first line contains two integers .
- Each of the next lines contains integers , the range of bays accepted by bus .
Output
Print a single integer: the largest number of consecutive buses from the start that can be served.
Subtasks
- Subtask 1 (25 points): ; for every .
- Subtask 2 (25 points): ; for every .
- Subtask 3 (25 points): ; and for every .
- Subtask 4 (25 points): ; for every .
Examples
Example 1
Input
4 3
1 4
1 1
1 1
Output
2
Explanation: Assign bus to bay and bus to bay . Bus also requires bay , which is occupied, so three buses cannot be served; the answer is .
Example 2
Input
4 6
1 2
1 2
1 3
1 3
2 4
1 4
Output
3
Explanation: The first three buses can use bays . Bus accepts only bays , which are all occupied; therefore the maximum prefix contains buses.
Liên quan
Trong các cuộc thi sau: