GC-Ratio
Time limit2sMemory limit128 MB
Find the contiguous segment of length at least L with the largest share of ones, breaking ties by shorter length then earlier start.
- Level
Medium7 of 10
- Topics
- Binary search, Prefix sum
- Solved
- No attempts yet
Problem
A DNA sequence is made up of the letters A, C, G, and T. The GC-ratio of a DNA sequence is the number of C and G divided by the length of the sequence. Regions with a high GC-ratio are more likely to be the start of a gene, so the GC-ratio is an important measure.
Research often looks for the substring (a contiguous segment) with the largest GC-ratio inside a very long DNA sequence. Because short substrings with a high GC-ratio are usually meaningless, a lower bound on the length is fixed, and only substrings of length at least are considered.
If every A and T is replaced by and every C and G by , the DNA sequence becomes a binary sequence of the same length. The average value of this binary sequence equals the GC-ratio of the original DNA sequence.
For the binary sequence above, if the lower bound is , the substring with the maximum average is with average . If the lower bound is , the substring with the maximum average is with average .
Given a binary sequence and a length lower bound , write a program that finds the substring with the maximum average among all substrings of length at least . If several substrings share the maximum average, choose the one with the shortest length; if several of those exist, choose the one with the earliest starting position.
Input
The first line contains the number of test cases . Each test case consists of two lines. The first line contains the length of the binary sequence and the length lower bound (, ). The second line contains the binary sequence of length .
Output
For each test case, print the starting position and the ending position of the chosen substring on one line, separated by a space. Positions are counted from .