#P3602. Koishi and Line Segments
Koishi and Line Segments
Koishi and Line Segments
Koishi loves line segments. She has a collection of (n) segments, each represented as a closed interval ([l, r]) on the real number line. She would like to place some of these segments on the number line so that she can enjoy counting how many segments cover certain points.
However, her friend Flandre has posed a challenge: there are (m) special points on the number line. If any of these points is covered by more than (x) segments, that point becomes uncomfortable and criticizes Koishi. To keep every special point comfortable (i.e. each special point is covered by at most (x) segments), Koishi wants to select a maximum subset of her segments to place on the line.
Given the (n) segments and the (m) special points, help Koishi remove as few segments as possible so that for every special point (p), the total number of segments covering (p) does not exceed (x). In other words, choose as many segments as possible from the given collection subject to the constraint that for every special point (p), (#{\text{segments } [l,r] : l\le p\le r}\le x).
Note: A segment ([l, r]) is said to cover a point (p) if (l \le p \le r). If multiple answers exist, output any valid solution that results in the minimum number of removed segments.
inputFormat
The first line contains three integers (n), (m), and (x) (the number of segments, the number of special points, and the maximum allowed coverage per special point).
The next (n) lines each contain two integers (l) and (r) representing a segment ([l, r]).
The last line contains (m) integers representing the coordinates of the special points.
outputFormat
On the first line, output a single integer (k) which is the number of segments to remove.
On the second line, output (k) space‐separated integers — the indices of the segments to remove, in increasing order. The segments are numbered from 1 to (n) in the order of input. If no segment needs to be removed, output 0 on the first line and leave the second line empty.
sample
3 2 1
1 4
2 6
6 9
3 7
1
2
</p>