#P3602. Koishi Loves Segments
Koishi Loves Segments
Description
Koishi likes segments.
Each of her segments can be represented as a closed interval on the number line. Koishi likes to put all the segments on the number line and then count how many segments cover certain points.
Seeing how happily she plays with segments, Flandre throws her a problem:
There are points on the number line that suddenly get excited. If a point is covered by more than segments, it will feel terrible and criticize Koishi.
Koishi is very kind. To avoid making the points feel bad and to make herself happy, she wants to place as many segments on the number line as possible.
As usual, Koishi pretends she cannot solve this problem, so she asks you for help, and promises to give you a phone call if you solve it.
Input Format
The first line contains two integers , denoting the number of segments to insert and the number of excited points.
Each of the next lines contains two integers (), denoting the endpoints of a segment .
Each of the next lines contains two integers , meaning that the point at position gets excited and requires that it should not be covered by more than segments.
Output Format
Output a single integer, denoting the maximum number of segments that can be placed.
4 3
1 3
2 4
5 7
6 8
2 5
3 1
6 2
3
Hint
- For 20% of the testdata, .
- For 60% of the testdata, .
- For 80% of the testdata, .
- Constraints: , , .
- If a point gets excited multiple times, Koishi should satisfy its stricter requirement (i.e., when is the same, take the minimum ).
- Please use fast I/O appropriately.
Translated by ChatGPT 5
京公网安备 11011102002149号