From up to 10 offers, choose the fewest that cover sections 1 to 10000 using at most 3 distinct colors.
Medium4Brute forceIntervalsGreedyInterviewNo attempts yetTime limit5sMemory limit512 MBYou need to hire people to paint a fence. The fence is 10000 contiguous sections, numbered 1 to 10000.
Painters send you offers. Each offer is to paint one contiguous range of sections in one color. You have to accept a set of the offers so that both of these hold.
If both conditions can be satisfied, find the minimum number of offers you must accept.
Two accepted offers may overlap. Two colors are the same color only when their strings are equal.
The first line contains the number of test cases T.
Each test case is given as follows.
C A B. C is the color, an uppercase letter string of length at most 10. A is the first section and B is the last section to be painted, with 1≤A≤B≤10000.Limits
Print one line per test case, in the order the cases are given, in the form Case #X: Y, where X is the case number and Y is the minimum number of offers that must be accepted. If no set of offers satisfies the conditions, print Case #X: IMPOSSIBLE on that line instead.
These are the five test cases of the sample input.