Angry professor problem solution
This problem is taken from Hakerrank :
A Discrete Mathematics professor has a class of  students. Frustrated with their lack of discipline, he decides to cancel
class if fewer than  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 , the number of test cases. 
Each test case consists of two lines. The first line has
two space-separated integers,  (students in the class) and  (the cancelation threshold). 
The second line contains space-separated integers () describing the arrival times for each student.
The second line contains space-separated integers () describing the arrival times for each student.
Note: Non-positive arrival times () indicate the student arrived early or on time; positive arrival times () indicate the student arrived  minutes late.
Output Format
For each test case, print the word YES if the
class is canceled or NO if it is not. 
Constraints 
Note 
If a student arrives exactly on time , the student is considered to have entered before the class started.
If a student arrives exactly on time , 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, . The professor wants at least  students in attendance, but only  have arrived on time ( and ). Thus, the class is canceled.
For the second test case, . The professor wants at least  students in attendance, and there are  who have arrived on time ( and ). Thus, the class is not canceled.
solution :
int main()
{
int
a[10],i,n,k,t,c;
scanf("%d",&t);
while(t!=0)
{     c=0;
      scanf("%d%d",&n,&k);
            for(i=0;i<n;i++)
{
      scanf("%d",&a[i]);
}
      for(i=0;i<n;i++)
{
      if(a[i]<0||a[i]==0  )
      c++;
}
      if(c==k)
printf("NO\n");
else
printf("YES\n");
t--;
}
   return 0;
}
 
Comments
Post a Comment