Skip to main content
Code Review

Return to Question

added 120 characters in body
Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

Problem Statement

Problem Statement

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 Format

###Input Format

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\$a_1,a_2,...,a_N\$, representing the arrival time of each student.

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

Output Format

###Output Format

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

Constraints

\1ドル≤T≤10, 1≤N≤1000, 1≤K≤N, −100≤ai≤100,where i∈[1,N]\$ ###Constraints

Note

$$\begin{align} 1&≤T≤10,\\ 1&≤N≤1000,\\ 1&≤K≤N,\\ −100&≤a_i≤100, \text{where}\ i∈[1,N] \end{align}$$

If###Note If a student enters the class exactly when it starts (ai=0\$a_i=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 Input

2
4 3
-1 -3 4 2
4 2
0 -1 2 1

Sample Output

###Sample Output

YES
NO
YES
NO

Solution

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"

Problem Statement

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 Format

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 Format

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

Constraints

\1ドル≤T≤10, 1≤N≤1000, 1≤K≤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

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"

Problem Statement

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 Format

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,\$a_1,a_2,...,a_N\$, representing the arrival time of each student.

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

###Output Format

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

###Constraints

$$\begin{align} 1&≤T≤10,\\ 1&≤N≤1000,\\ 1&≤K≤N,\\ −100&≤a_i≤100, \text{where}\ i∈[1,N] \end{align}$$

###Note If a student enters the class exactly when it starts (\$a_i=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

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"
added 8 characters in body
Source Link
Mast
  • 13.8k
  • 12
  • 57
  • 127

Problem Statement

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 Format

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 Format

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

Constraints

\1ドル≤T≤10, 1≤N≤1000, 1≤K≤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

YES
NO

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"

Problem Statement

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 Format

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 Format

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

Constraints

\1ドル≤T≤10, 1≤N≤1000, 1≤K≤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

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"

Problem Statement

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 Format

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 Format

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

Constraints

\1ドル≤T≤10, 1≤N≤1000, 1≤K≤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

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"
Source Link
CodeYogi
  • 5.2k
  • 12
  • 50
  • 106

"Angry Professor" Python implementation

Problem Statement

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 Format

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 Format

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

Constraints

\1ドル≤T≤10, 1≤N≤1000, 1≤K≤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

Solution

def is_on_time(a):
 return a <= 0
def class_cancelled(expected, arrival_times):
 actual = map(lambda x: 1 if is_on_time(x) else 0, arrival_times).count(1)
 return actual >= expected
def read_int():
 return int(raw_input())
def read_ints():
 return map(int, raw_input().strip().split())
if __name__ == '__main__':
 T = read_int()
 for _ in xrange(T):
 N, K = read_ints()
 A = read_ints()
 print "NO" if class_cancelled(K, A) else "YES"
lang-py

AltStyle によって変換されたページ (->オリジナル) /