- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAngryProfessor.java
More file actions
Latest commit
94 lines (69 loc) · 2.44 KB
/
Copy pathAngryProfessor.java
File metadata and controls
94 lines (69 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
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 (a1,a2,…,aN) describing the arrival times for each student.
Note: Non-positive arrival times (ai≤0) indicate the student arrived early or on time; positive arrival times (ai>0) indicate the student arrived ai minutes late.
Output Format
For each test case, print the word YES if the class is canceled or NO if it is not.
Constraints
1≤T≤10
1≤N≤1000
1≤K≤N
−100≤ai≤100,where i∈[1,N]
Note
If a student arrives exactly on time (ai=0), the student is considered to have entered before the class started.
*/
importjava.io.*;
importjava.util.*;
importjava.text.*;
importjava.math.*;
importjava.util.regex.*;
importjava.util.Arrays;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannerin = newScanner(System.in);
intt = in.nextInt();
for(inta0 = 0; a0 < t; a0++){
intn = in.nextInt();
intk = in.nextInt();
inta[] = newint[n];
for(inta_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
booleanresult[]=newboolean[n];
for(inti=0;i<n;i++)
{
result[i]=true;
}
for(inti=0;i<n;i++)
{
if(a[i]>0)
{
result[i]=false;
}
}
// System.out.println(Arrays.toString(result));
intcount=0;
for(inti=0;i<n;i++)
{
if(result[i]==true)
{
count++;
}
}
// System.out.println(count);
//System.out.println(n);
if(count>=k)
{
System.out.println("NO");
}
else
{
System.out.println("YES");
}
}
}
}