Macbeth
Time limit2sMemory limit512 MB
Given n time intervals and w witches, each witch predicts a chain of non-overlapping intervals, so find the maximum number of intervals coverable by w chains.
- Level
Medium6 of 10
- Topics
- Intervals, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
Macbeth is a loyal follower of the king, and he has just fought well in a battle. Then he meets three witches. They predict that he is about to be promoted, and that he will become king after that. The promotion happens exactly as predicted, so Macbeth starts to believe that he is destined to be king. He and his wife go blind with ambition, murder the king, and murder almost everyone they see as a threat or a rival.
The witches held that much power over Macbeth because their prediction was right. Macbeth should have asked for more than one prediction and made their job harder. Predicting with a crystal ball is hard work. A ball is fussy about when it lets you predict a particular event, and some predictions take longer than others. Working out how to make the largest number of predictions together is a difficult task for the witches.
Every event comes with one time interval. To predict event , one witch has to look into her crystal ball for the whole interval while thinking about event only. So even when two events share the same interval, a single witch predicts only one of them. A witch who has predicted event can predict event next only when . The witches coordinate so that the total number of predicted events is as large as possible.
Given witches, find the maximum number of events they can predict.
Input
The first line contains the number of data sets . Then data sets follow, each in the format below.
The first line of a data set contains two integers and . is the number of events and is the number of witches.
Each of the next lines contains two integers and describing one event ().
Output
For each data set, first print Data Set x: on a line by itself, where is the number of the data set counting from 1. On the next line print the maximum number of events the witches can predict.
Print one blank line after each data set.