#Lutece0675. Road Series
Road Series
Migrated from Lutece 675 Road Series
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Don and Jan spend a lot of time together on the road. To pass the time, they've invented various games they can play, many of which involve license plates and road signs. One of their favorites is Road Series.
The object is to find the number on some sign, then , then , and so on. When they get to two digit numbers the two digits must appear directly next to each other on the sign or license plate, and any sign or license plate can provide multiple answers. For example, if they see a sign with the characters 678-43 15
, they can use the numbers , , and but not (dash between the two digits) or (space between the two digits). They could also use the individual digits , , , , , and as well as the three digit number (if they got up that high)
When they first started playing the game, they had very strict rules about when you could find a number, namely you weren't allowed to find a number n until all the numbers through were already found. They soon found that this made the game REALLY slow, so they modified the game as follows. First, they called a number n the last complete number if it was the highest number such that all the numbers from to had been found. (Initially, is the last complete number.)
Given this, Don and Jan allowed themselves to keep track of having seen some numbers beyond the last complete number , so long they weren't too much bigger than . More precisely, they can keep track of which numbers they've seen in a window of size beyond . This allows them to remember any number they've seen up to .
For example, suppose and and the last complete number Don and Jan have seen is . When they see the following sign:
Show time at 8:25, no one under 21 admitted
they can use the , but not the (since it's not in the window). If this sign is followed by the sign:
The FleaBag Hotel, phone 555-2520
they can use the , which now makes the last complete number, and thus can also use the , since it's now in the window.
Input
The first line of the input file will contain an integer m indicating the number of test cases. Each test case will start with a pair of positive integers , , where indicates the number of signs seen by Don and Jan, and indicates the window size. Following that will be lines each consisting of text from a sign. Each line of text may contain any combination of alphanumeric characters, punctuation and spaces, and will have length at most . Input for each sign will end with a new line.
Output
For each test case, output the case number followed by the last complete number that can be found using the signs, followed by the highest number seen within the window.
Samples
4
2 10
13
2
2 10
2
13
1 8
Tomorrow, from 12 to 2, 4-4 basketball tournament! $3 entry fee.
1 8
Tomorrow, from 11 to 7, 4-4 basketball tournament! $3 entry fee.
Case 1: 3 3
Case 2: 3 13
Case 3: 4 12
Case 4: 1 7
Resources
2012 East Central Regional Contest