finding-sequence-unique-for-k-numbers

The professor is conducting a course on Discrete Mathematics to a class of N students. He is angry at the lack of their discipline, and he decides to cancel the class if there are fewer than K students present after the class starts.

Given the arrival time of each student, your task is to find out if the class gets cancelled or not.

INPUT

The first line of the input contains T, the number of test cases. Each test case contains two lines.
The first line of each test case contains two space-separated integers, N and K.
The next line contains N space-separated integers, a1,a2,…,aN, representing the arrival time of each student.

If the arrival time of a given student is a non-positive integer (ai≤0), then the student enters before the class starts. If the arrival time of a given student is a positive integer (ai>0), the student enters after the class has started.

OUTPUT

For each testcase, print "YES" (without quotes) if the class gets cancelled and "NO" (without quotes) otherwise. 

CONSTRAINT

1≤T≤10

1≤N≤1000

1≤N≤

−100≤ai≤100,where i∈[1,N]

NOTE

If a student enters the class exactly when it starts (ai=0), the student is considered to have entered before the class has started.

SAMPLE INPUT
2
4 3
-1 -3 4 2
4 2
0 -1 2 1

SAMPLE OUTPUT
YES
NO

Explanation

For the first test case, K=3, i.e., the professor wants at least 3 students to be in class but there are only 2 who have arrived on time (−3 and −1), hence the class gets cancelled.

For the second test case, K=2, i.e, the professor wants at least 2 students to be in class and there are 2 who have arrived on time (0 and −1), hence the class does not get cancelled.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
T=eval(input())
for i in range(T):
	a,b=list(map(int,input().split()))
	c=list(map(int,input().split()))
	count=0
	for j in c:
		if j<=0:
			count+=1
	if count<b:
		print("YES")
	else:
		print("NO")


tc=int(input())
for case in range(tc):
	n,k=list(map(int,input().split()))
	a=list(map(int,input().split()))
	c=0
	for i in a:
		if i<=0:
			c=c+1
	if c<k:
		print("YES")
	else:
		print("NO")


kases = int(eval(input()))
for kase in range(kases*2):
	in_lst = input().split()
	if len(in_lst) == 2:
		N = int(in_lst[0])
		K = int(in_lst[1])
	cnt = 0
	if len(in_lst) > 2:
		for value in in_lst:
			if int(value) <= 0:
				cnt = cnt + 1
		if cnt < int(K):
			print('YES')
		else:
			print('NO')


t=eval(input())
for _ in range (t):
	n,k=list(map(int,input().split()))
	a=list(map(int,input().split()))
	a=sorted(a)
	c=0
	i=0
	while a[i]<=0:
		c+=1
		i+=1
	if c>=k:
		print('NO')
	else:
		print('YES')


if __name__=='__main__':
	T = int(input())
	for i in range(0,T):
		N,M= list(map(int,input().split()))
		numlist = list(map(int,input().split()))
		count = 0
		for i in numlist:
			if i <= 0:
				count += 1
		if count >= M:
			print("NO")
		else:
			print("YES")


t=eval(input())
while t>0:
	co=0
	t=t-1
	p,q=list(map(int,input().split()))
	a=list(map(int,input().split()))
	for i in  a:
		if i<=0:
			co=co+1
	if co<q:
		print("YES")
	else:
		print("NO")
			


t=int(input())
while t>0:
	n,k=list(map(int,input().split(" ")))
	a=list()
	a=list(map(int,input().split(" ")))
	cnt=0
	for i in range(n):
		if a[i]<=0:
			cnt+=1
	if cnt>=k:
		print("NO")
	else:
		print("YES")
	t-=1


t=eval(input())
for j in range(t):
	a=[]
	x,y=list(map(int,input().split()))
	a=list(map(int,input().strip().split()))
	count=0;
	for i in a:
		if i<=0:
			count+=1
	if count>=y:
		print("NO")
	else:
		print("YES")
		


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = int(eval(input()))
while t > 0:
	flag = 0
	n,k = [int(x) for x in input().split()]
	count = 0
	num = [int(x) for x in input().split()]
	for i in num:
		if i <= 0:
			count += 1
		if count >= k:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')
	t -= 1




if __name__ == '__main__':
	t = eval(input())
	for _ in range(t):
		n, m = list(map(int, input().split()))
		A = list(map(int, input().split()))
		for x in A:
			if x <= 0:
				m -= 1
		if m <= 0:
			print("NO")
		else:
			print("YES")