#P8317. Super Lucky Interval
Super Lucky Interval
Super Lucky Interval
A lottery event is underway. Each participant is given n sequences. Each sequence consists of d positive integers. In addition, a number k is provided which indicates that among all the positive integers appearing in these sequences, exactly k of them are designated as lucky numbers.
A participant may choose a contiguous block (interval) of the sequences. Such an interval is called a lucky interval if it is possible to select a set L of k lucky numbers (from the numbers that appear in the sequences overall) such that, for every sequence in that interval, at least one number in the sequence belongs to L. Note that there may be several lucky intervals. The super lucky interval is defined as the lucky interval having the maximum number of sequences (i.e. the longest interval). In case multiple intervals have the same maximum length, choose the one with the smallest starting index. Indices are 0-based.
Example: Consider the case with d = 2 and k = 3 with the following 6 sequences:
- Sequence 0: 115 120
- Sequence 1: 50 80
- Sequence 2: 199 30
- Sequence 3: 40 40
- Sequence 4: 30 30
- Sequence 5: 25 40
One can show that the interval from sequence 0 to sequence 2 is a lucky interval because one may choose L = \(\{120, 50, 30\}\) so that each sequence in the interval contains at least one lucky number. Another possible lucky interval is from sequence 1 to sequence 5 since with L = \(\{80, 30, 40\}\) every sequence in the interval is hit by at least one lucky number. Since the interval from sequence 1 to sequence 5 has 5 sequences which is the maximum possible, it is the super lucky interval.
Your task is: Given n, d and k followed by the n sequences (each consisting of d positive integers), find the super lucky interval and output the first and last indices of that interval.
Note: The term "lucky interval" means that there exists a set L of exactly k numbers (or fewer, which can always be padded to size k) such that each sequence in that interval contains at least one element from L. You may assume that if an interval of length at least 1 is possible, then single sequences are always lucky intervals.
inputFormat
The first line contains three integers n, d and k, where n is the number of sequences, d is the number of integers in each sequence, and k is the size of the lucky set.
Then follow n lines, each containing d positive integers separated by spaces.
outputFormat
Output two integers separated by a space representing the starting index and ending index of the super lucky interval.
sample
6 2 3
115 120
50 80
199 30
40 40
30 30
25 40
1 5