Angry Professor

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 (ai0), 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

  • 1T10
  • 1N1000
  • 1KN
  • 100ai100,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.

 

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int loops=0;
    cin>>loops;
    for(int i=0; i<loops; i++){
        int students=0, threshold=0, on_time=0, arrive_time=0;
        cin>>students;
        cin>>threshold;
        for(int j=0; j<students; j++){
            cin>>arrive_time;
            if(arrive_time<=0) on_time++;
            //cout<<arrive_time<<" "<<on_time<<endl;
        }
        if(on_time>=threshold) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/XingyingLiu/p/4946885.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值