Deleting Segments
Time limit1sMemory limit1024 MB
Delete the cheapest set of segments on a number line so that no group of mutually connected overlapping segments has more than K members.
- Level
Medium6 of 10
- Topics
- Intervals, Dynamic programming, Sorting
- Solved
- No attempts yet
Statement
A number line has segments numbered . Segment has endpoints and . Consider a graph with one vertex per segment, where two vertices are connected by an edge if their segments share at least one point (even if they only share an endpoint).
You must make sure that no connected component of this graph has more than vertices. To do this, you may delete some of the given segments. Deleting segment costs a fixed price . Find a way to delete segments with the minimum total price.
Input
The first line contains integers and (). Each of the next lines describes one segment with three integers , , and (, ).
Output
Print the minimum total price of the deletions on a single line.