Read problems statements in Mandarin Chinese  and Russian. 

Today is chef's friend's birthday. He wants to give a gift to his friend. So he was desperately searching for some gift here and there. 

Fortunately, he found an array a of size n lying around. The array contains positive integers. Chef's friend likes even numbers very much. So for the gift, chef will choose a  consecutive non-empty segment of the array. The segment should contain exactly k even integers. Though it can have any number of odd integers.
He will then pick that segment and gift it to his friend. 

But there is a problem. It might not be always possible for the chef to choose such a segment. Please tell whether it is possible for chef to select some gift or not?

------ Input ------ 

First line of the input contains a single integer  T  denoting number of test cases. 
For each test case, first line contains two space separated integers n, k. 
Next line contains n space separated integers denoting content of array a. 
It is also guaranteed that all the numbers in the array a are distinct. 

------ Output ------ 

For each test case, print a single line containing "YES" or "NO" (without quotes) corresponding to the situation.

------ Constraints ------ 

$1 ≤ T ≤ 10$
$1 ≤ n ≤ 50$
$0 ≤ k ≤ n$
$1 ≤ a _{i } ≤ 100$

------  Note  ------ 

A consecutive non empty segment of array a is a segment a[l], a[l + 1] , , a[r] such that 1 ≤ l ≤ r ≤ n. 

----- Sample Input 1 ------ 
4
2 1
1 2
3 2
2 6 5
3 3
2 4 5
4 2
1 2 4 5
----- Sample Output 1 ------ 
YES
YES
NO
YES
----- explanation 1 ------ 

For  first  test case, we can select a[2, 2] = {2}. 
For second  test case, we can select a[1, 2] = {2, 6}. 
For third  test case, we can not select any consecutive segment having exactly 3 even numbers. 
For fourth  test case, we can select a[2, 3] = {2, 4}.

Difficulty: MEDIUM
Tags: Constructive algorithms

Ad-hoc

Starter code:

Solutions:
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	count = 0
	for i in l:
		if i % 2 == 0:
			count += 1
	if k == 0:
		if n - count == 0:
			print('NO')
		else:
			print('YES')
	elif count >= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	c = 0
	for i in a:
		if i % 2 == 0:
			c += 1
	if c < k or (k == 0 and c == n):
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	c = 0
	(p, q) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in l:
		if i % 2 == 0:
			c += 1
	if c < q or (q == 0 and c == p):
		print('NO')
	elif c >= q:
		print('YES')
	t -= 1


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	poss = 0
	for ele in arr:
		if ele % 2 == 0:
			poss += 1
	if poss < k or (k == 0 and poss == n):
		print('NO')
	elif poss >= k:
		print('YES')


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	count = 0
	for i in range(x):
		if l[i] % 2 == 0:
			count += 1
	if count < y or (y == 0 and count == x):
		print('NO')
	elif count >= y:
		print('YES')


t = int(input())
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	a = [int(x) for x in input().split()]
	if n == 0:
		print('NO')
		continue
	c = 0
	for i in a:
		if i % 2 == 0:
			c += 1
	if k == 0 and c == n:
		print('NO')
	elif c >= k:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	count = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			count += 1
	if count < k or (k == 0 and count == n):
		print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	e = 0
	for i in l:
		if i & 1 == 0:
			e = e + 1
	if k == 0 and n == e:
		print('NO')
	elif e >= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = 0
	for i in arr:
		if i % 2 == 0:
			c += 1
	if k == 0 and c == n:
		print('NO')
		continue
	if c >= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(array_size, wanted) = list(map(int, input().split()))
	array = list(map(int, input().split()))
	lit = [x for x in array if x % 2 == 0]
	if wanted == 0:
		if array_size - len(lit) == 0:
			print('NO')
		else:
			print('YES')
	elif len(lit) >= wanted:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	for i in a:
		if i % 2 == 0:
			c += 1
	if k == 0 and c == n:
		print('NO')
	elif c >= k:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	(n, k) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	count = 0
	m = 0
	flag = 0
	for i in l:
		if i % 2 == 0:
			count += 1
	if k == 0 and count == n:
		print('NO')
	elif count >= k:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
while t:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	for i in l:
		if i % 2 == 0:
			c += 1
	if k == 0:
		print('NO' if c == n else 'YES')
	else:
		print('YES') if c >= k else print('NO')
	t -= 1


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in range(len(a)):
		if a[i] % 2 == 0:
			s += 1
	if k == 0 and s == len(a):
		print('NO')
	elif s < k:
		print('NO')
	else:
		print('YES')


T = int(input())
while T:
	T -= 1
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = 0
	for i in a:
		if not i % 2:
			b += 1
	if b == n and (not k):
		print('NO')
	elif b >= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	counter = 0
	for i in l1:
		if i % 2 == 0:
			counter += 1
	if counter == n and k == 0:
		print('NO')
	elif counter >= k:
		print('YES')
	else:
		print('NO')


for x in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 0
	for y in l:
		if y % 2 == 0:
			i = i + 1
	if k == 0 and i == n:
		print('NO')
	elif k <= i:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	li = list(map(int, input().split()))
	k = 0
	for i in li:
		if i % 2 == 0:
			k += 1
	if b == 0 and k == a:
		print('NO')
	elif b <= k:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	cnt = 0
	for i in arr:
		cnt += i % 2 == 0
	if k == 0 and cnt == n:
		print('NO')
	elif cnt >= k:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ev = 0
	for i in l:
		if i % 2 == 0:
			ev += 1
	if k == 0 and ev == n:
		print('NO')
		continue
	if ev >= k:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	even = 0
	for i in a:
		if i % 2 == 0:
			even += 1
	if k == 0:
		if even < n:
			print('YES')
		else:
			print('NO')
		continue
	if even < k:
		print('NO')
		continue
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	eve = len([n for n in arr if n % 2 == 0])
	if k == 0 and eve == n:
		print('NO')
	elif eve >= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	count = 0
	for i in range(n):
		if s[i] % 2 == 0:
			count += 1
	if k == 0:
		if count < n:
			print('YES')
		else:
			print('NO')
		continue
	if count >= k:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(N, K) = [int(x) for x in input().split()]
	arr = list(map(int, input().split()))
	d = {}
	d['E'] = 0
	d['O'] = 0
	for i in arr:
		if i % 2 == 0:
			d['E'] += 1
		else:
			d['O'] = 1
	if K == 0:
		if d['E'] < N:
			print('YES')
		else:
			print('NO')
		continue
	elif d['E'] >= K:
		print('YES')
		continue
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	even_num_count = 0
	for item in a:
		if item % 2 is 0:
			even_num_count += 1
		else:
			continue
	if even_num_count < k or (k is 0 and even_num_count is n):
		print('NO')
	else:
		print('YES')


from itertools import combinations as cb
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	cnt = 0
	for i in range(N):
		if A[i] % 2 == 0:
			cnt += 1
	if cnt < K or (K == 0 and cnt == N):
		print('NO')
	else:
		print('YES')


get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
for _ in range(get_int()):
	(N, K) = get_mint()
	A = get_mint()
	cnt = 0
	for i in range(N):
		if A[i] % 2 == 0:
			cnt += 1
	if cnt < K or (K == 0 and cnt == N):
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
stdint = lambda : int(stdin.readline())
mul = lambda : map(int, stdin.readline().strip().split())
seq = lambda : list(map(int, stdin.readline().strip().split()))
for _ in range(stdint()):
	(n, k) = mul()
	nums = seq()
	count = 0
	for num in nums:
		if num % 2 == 0:
			count += 1
	if k == 0 and count < n:
		print('YES')
	elif k != 0 and k <= count:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(x, y) = list(map(int, input().split()))
	n = list(map(int, input().split()))
	count = 0
	for i in range(len(n)):
		if n[i] % 2 == 0:
			count += 1
	if y == 0 and count < x:
		print('YES')
	elif y != 0 and y <= count:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().rstrip().split()))
	s = 0
	for i in range(n):
		if ls[i] % 2 == 0:
			s += 1
	if k == 0 and s < n:
		print('YES')
	elif k != 0 and k <= s:
		print('YES')
	else:
		print('NO')


for z in range(int(input())):
	(n, k) = map(int, input().split())
	cnt = 0
	l = list(map(int, input().split()))
	for i in l:
		if i % 2 == 0:
			cnt += 1
	if k == 0 and cnt < n:
		print('YES')
	elif k != 0 and k <= cnt:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	even = 0
	cnt = 0
	b = False
	for i in range(n):
		if l[i] % 2 == 0:
			cnt = 1
			even += 1
			for j in range(i + 1, n):
				if l[j] % 2 == 0:
					cnt += 1
				if cnt == k:
					b = True
					break
		if cnt == k:
			b = True
		if b:
			break
	if b or (k == 0 and even != n):
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	for x in l:
		if x % 2 == 0:
			c += 1
	if c < k or (k == 0 and c == n):
		print('NO')
	else:
		print('YES')
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	count1 = 0
	odd = 0
	for z in list1:
		if z % 2 == 0:
			count1 += 1
		else:
			odd = 1
	if k == 0:
		if odd == 1:
			print('YES')
		else:
			print('NO')
	elif count1 >= k:
		print('YES')
	else:
		print('NO')


tst = int(input())
for i in range(tst):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = 0
	d = 0
	for j in range(n):
		if arr[j] % 2 == 0:
			c = c + 1
		else:
			d = d + 1
	if k == 0:
		if d > k:
			print('YES')
		else:
			print('NO')
	elif c >= k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = [int(x) for x in input().split()]
	even = len(list(filter(lambda n: n % 2 == 0, list1)))
	if even < k or (k == 0 and even == n):
		print('NO')
	else:
		print('YES')


for k in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	e = 0
	for i in a:
		if i % 2 == 0:
			e += 1
	if e < k or (k == 0 and e == n):
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	for i in a:
		if i % 2 == 0:
			c += 1
	if c == n and k == 0 or c < k:
		print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	for i in l:
		if i % 2 == 0:
			c += 1
	if c < k or (c == n and k == 0):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	even = 0
	for i in range(n):
		if arr[i] % 2 == 0:
			even += 1
	if k == 0 and even == n:
		print('NO')
	elif even < k:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	(N, K) = [int(i) for i in input().split(' ')]
	A = [int(i) for i in input().split(' ')]
	if K == 0:
		hasOdd = False
		for i in range(N):
			if A[i] & 1:
				hasOdd = True
				break
		print('YES' if hasOdd else 'NO')
		continue
	count = 0
	for i in range(N):
		if not A[i] & 1:
			count += 1
		if count == K:
			print('YES')
			break
	if count < K:
		print('NO')


for i in range(int(input())):
	l = input().split(' ')
	n = int(l[0])
	k = int(l[1])
	l1 = input().split(' ')
	l2 = []
	l3 = []
	for i in l1:
		l2.append(int(i))
	for i in l2:
		if i % 2 == 0:
			l3.append(i)
		else:
			pass
	if len(l3) < k or (k == 0 and len(l3) == n):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ev = []
	for i in range(n):
		if arr[i] % 2 == 0:
			ev.append(arr[i])
	if len(ev) < k or (k == 0 and len(ev) == n):
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = 0
	for j in a:
		if j % 2 == 0:
			cnt += 1
	if cnt < k or (k == 0 and cnt == n):
		print('NO')
	else:
		print('YES')
	t -= 1


tests = int(input())
for i in range(tests):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	even = 0
	for j in arr:
		if j % 2 == 0:
			even += 1
	if even < k or (k == 0 and even == n):
		print('NO')
	else:
		print('YES')


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	count = 0
	for j in arr:
		if j % 2 == 0:
			count += 1
	if k == 0 and count == n:
		print('NO')
	elif count >= k:
		print('YES')
	else:
		print('NO')


def count(l):
	c = 0
	for i in l:
		if i % 2 == 0:
			c += 1
	return c
t = int(input())
for i in range(t):
	z = 0
	(n, k1) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(n):
		for k in range(j + 1, n + 1):
			if count(a[j:k]) == k1:
				z = 1
				break
	if z == 0:
		print('NO')
	else:
		print('YES')