daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 63 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. import java.util.Scanner;
  2.  
  3. public class Solution {
  4.  
  5.     private static Scanner scanner = new Scanner(System.in);
  6.  
  7.     public static void main(String[] args) {
  8.         int numberOfTestCases = scanner.nextInt();
  9.  
  10.         for (int i = 0; i < numberOfTestCases; i++) {
  11.             printIfClassIsCancelled();
  12.         }
  13.  
  14.         scanner.close();
  15.     }
  16.  
  17.     private static void printIfClassIsCancelled() {
  18.         int numberOfStudents = scanner.nextInt();
  19.         int minimumAttendance = scanner.nextInt();
  20.  
  21.         int[] students = readArray(numberOfStudents);
  22.  
  23.         if (isClassCanceled(students, minimumAttendance)) {
  24.             System.out.println("YES");
  25.         } else {
  26.             System.out.println("NO");
  27.         }
  28.     }
  29.  
  30.     private static boolean isClassCanceled(int[] students, int minimumAttendance) {
  31.         int studentsArrivedOnTime = 0;
  32.         for (int i = 0; i < students.length; i++) {
  33.             if (students[i] <= 0) {
  34.                 studentsArrivedOnTime++;
  35.                 if (studentsArrivedOnTime >= minimumAttendance) {
  36.                     return false;
  37.                 }
  38.             }
  39.         }
  40.  
  41.         return true;
  42.     }
  43.  
  44.     private static int[] readArray(int length) {
  45.         int[] array = new int[length];
  46.  
  47.         for (int i = 0; i < length; i++) {
  48.             array[i] = scanner.nextInt();
  49.         }
  50.  
  51.         return array;
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top