Can't Stop (Small)
Time limit5sMemory limit512 MB
Find the longest consecutive run of roll sets where every set contains at least one of k chosen numbers.
- Level
Medium6 of 10
- Topics
- Sliding window, Backtracking
- Solved
- No attempts yet
Problem
This problem takes its idea from the board game Can't Stop, designed by Sid Sackson. You do not need to have played that game.
You are playing a very large board game. The game hands you a sequence of roll sets. Each roll set holds die rolls, and every die roll is an integer.
To win the game you have to find the largest totally awesome interval of the sequence. An interval is any run of consecutive roll sets. An interval is totally awesome if there are numbers such that every roll set in the interval contains at least one of those numbers.
Take , and these roll sets:
The interval from set 0 to set 2 is totally awesome, because sets 0, 1 and 2 all contain 10, 50 or 70. The interval from set 1 to set 5 is totally awesome, because sets 1 through 5 all contain 50, 30 or 40. That interval holds 5 roll sets, and no totally awesome interval of this sequence is longer.
Print the indices of the first and the last roll set of the longest totally awesome interval. When several totally awesome intervals reach that length, print the one whose first index is smallest. The first roll set has index 0.
Input
The first line holds the number of test cases . The test cases follow. Each test case starts with three integers , and separated by spaces. The next line holds integers. The first integers are the rolls of the first roll set, the next integers are the rolls of the second roll set, and so on.
Limits
- Every die roll is an integer between 1 and .
- At most 6 test cases have . Every other test case has .
Output
For each test case, print one line holding Case #x: y z, where x is the test case number starting from 1, and y and z are the first and the last index of the longest totally awesome interval. Ties are broken by the smallest first index.
Hint
The board game Can't Stop was designed by Sid Sackson, and several publishers have released it. Neither Sid Sackson nor any of those publishers endorses this problem or is involved with it.