TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the number of
Cs and Gs of the sequence divided by the length of the sequence. GC-ratio is important in gene finding
because DNA sequences with relatively high GC-ratios might be good candidates for the starting parts of
genes. Given a very long DNA sequence, researchers are usually interested in locating a subsequence whose
GC-ratio is maximum over all subsequences of the sequence. Since short subsequences with high GC-ratios
are sometimes meaningless in gene finding, a length lower bound is given to ensure that a long subsequence
with high GC-ratio could be found. If, in a DNA sequence, a 0 is assigned to every A and T and a 1 to every C
and G, the DNA sequence is transformed into a binary sequence of the same length. GC-ratios in the DNA
sequence are now equivalent to averages in the binary sequence.



For the binary sequence above, if the length lower bound is 7, the maximum average is 6/8 which happens in
the subsequence [7,14]. Its length is 8, which is greater than the length lower bound 7. If the length lower
bound is 5, then the subsequence [7,11] gives the maximum average 4/5. The length is 5 which is equal to the
length lower bound. For the subsequence [7,11], 7 is its starting index and 11 is its ending index.


Given a binary sequence and a length lower bound L, write a program to find a subsequence of the binary
sequence whose length is at least L and whose average is maximum over all subsequences of the binary
sequence. If two or more subsequences have the maximum average, then find the shortest one; and if two or
more shortest subsequences with the maximum average exist, then find the one with the smallest starting
index.

Input Format

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is
given in the first line of the input. Each test case starts with a line containing two integers n (1≤n≤100,000)
and L (1≤L≤1,000) which are the length of a binary sequence and a length lower bound, respectively. In the
next line, a string, binary sequence, of length n is given

Output Format

Your program is to write to standard output. Print the starting and ending index of the subsequence.


The following shows sample input and output for two test cases.

Sample Input 1

2 
17 5 
00101011011011010 
20 4 
11100111100111110000

Sample Output 1

7 11
6 9

Hints

Problem Source

Migrated from old NTUJ.

2009Seoul

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 65536 200