#P10052. [CCO 2022] Double Attendance
[CCO 2022] Double Attendance
Problem Description
Because your school’s schedule is so strange, your two classes will start at the same time in two different classrooms. You can only be in one place at a time, so you can only walk back and forth between the two rooms, hoping to catch the key parts of both classes.
The two classrooms are numbered and . In classroom , the teacher will show different slides. The -th slide is shown during the time interval $\left(A_{i, j}, B_{i, j}\right)\left(0 \leq A_{i, j}<B_{i, j}\right)$, where and are times in seconds measured from the start of the class. In each classroom, there will never be multiple slides shown at the same time. For example, a class may show slides during and , or during and , but it will not show slides during and .
You start the day in classroom , and both classes start at time . After that, at any moment (not necessarily an integer second), you may spend seconds moving from your current classroom to the other one. If you spend a positive amount of time in the correct classroom during a slide’s time interval, then you are considered to have seen that slide. During the seconds while you are moving between classrooms, you are in neither classroom, so you cannot see any slides.
For example, if classroom shows a slide during , classroom shows a slide during , and , then if you move from classroom to classroom at time seconds (arriving at time seconds), you can see both slides. On the other hand, if you leave classroom at time seconds (arriving at time seconds), then you will enter classroom only after its slide stops being shown, so you will miss it.
You want to know the maximum number of different slides you can see.
Input Format
The first line contains three integers , and , separated by spaces.
The next lines each contain two integers and , separated by spaces.
The next lines each contain two integers and , separated by spaces.
Output Format
Output one integer, the maximum number of different slides you can see.
3 1 8
10 20
100 101
20 21
15 25
3
1 5 3
1 100
1 2
2 3
3 4
4 5
5 6
4
Hint
Explanation for Sample 1
One possible optimal strategy is to stay in classroom until time , then move to classroom (arriving at time ), stay until time , and finally return to classroom (arriving at time ). During this process, you will see all slides except the -rd slide. It is impossible to see all slides.
Explanation for Sample 2
Even if you move to classroom immediately when the classes begin (for example, at time ), you will miss the first two slides shown there. Therefore, you can see at most four slides.
Constraints
For all testdata, , , .
| Subtask ID | Points | ||
|---|---|---|---|
Translated by ChatGPT 5