Angry Professor

Angry Professor

Angry Professor:

A Discrete Mathematics professor has a class of N students.Frustrated with their lack of discipline, he decides to cancel class if fewer than K students are present when class starts.Given the arrival time of each student, determine if the class is canceled.

Input Format

The first line of input contains T , the number of test cases. Each test case consists of two lines. The first line has two space-separated integers, N (students in the class) and K (the cancelation threshold). The second line contains N space-separated integers \(a_1\), \(a_2\),….\(a_N\) describing the arrival times for each student.

Note:

Non-positive arrival times \(a_i\)<=0 indicate the student arrived early or on time; positive arrival times \(a_i\)>0 indicate the student arrived \(a_i\) minutes late.

Constraints:
  • 1<=T <=10
  • 1<=N <=1000
  • 1<= K <=N
  • -100 <= \(a_i \) <=100 , where i E [1,N]
Output Format

For each test case, print the word YES if the class is canceled or NO if it is not.

Note:

If a student arrives exactly on time \(a_0\) = 0 , the student is considered to have entered before the class 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 . The professor wants at least 3 students in attendance, but only 2 have arrived on time (-3 and -1 ).Thus, the class is canceled.

For the second test case, K = 2 . The professor wants at least 2 students in attendance, and there are 2 who have arrived on time (0 and -1 ).Thus, the class is not canceled.

Solution

#!/bin/python

if __name__ == '__main__':
    t = input()
    for _ in xrange(t):
        n, m = map(int, raw_input().split())
        A = map(int, raw_input().split())
        for x in A:
            if x <= 0:
                m -= 1
        if m <= 0:
            print "NO"
        else:
            print "YES"
comments powered by Disqus