#K59972. Bird Migration Prediction
Bird Migration Prediction
Bird Migration Prediction
You are given a number of test cases. In each test case, you are provided with an integer N representing the length of a binary string, an integer L representing the length of a contiguous subsequence to examine, and a binary string of length N. Your task is to check if there exists any contiguous subsequence of length L in which the number of '1's is strictly greater than the number of '0's.
If such a subsequence exists, print YES
; otherwise, print NO
.
Note: All input should be read from the standard input and the output should be written to the standard output. Use appropriate algorithms to satisfy the constraints in a competitive programming setting.
The condition can be mathematically formulated as: Find an index \( i \) (\(1 \leq i \leq N-L+1\)) such that \[ \#1(i) > \#0(i), \] where \(\#1(i)\) and \(\#0(i)\) denote the number of ones and zeros in the substring of length L starting from i, respectively.
inputFormat
The input consists of multiple test cases. The first line contains an integer T
, the number of test cases. Each test case consists of two lines:
- The first line of each test case contains two integers separated by a space:
N
(the length of the binary string) andL
(the length of the contiguous subsequence). - The second line contains a binary string of length
N
.
All input is provided via the standard input.
outputFormat
For each test case, output a single line containing YES
if there exists a contiguous subsequence of length L with more '1's than '0's; otherwise, output NO
. All output should be written to the standard output.
3
7 3
1011010
5 2
01101
6 4
000011
YES
YES
NO
</p>