title: Maximum Removal From Array When Removal Time Waiting Time
signature: maximum_removal_from_array_when_removal_time_waiting_time <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(7L, 33L, 34L, 42L, 42L, 45L, 73L), 5L, 
          3L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-98L, -90L, -80L, -66L, -64L, -62L, -48L, -30L, -20L, -10L, 4L, 6L, 12L, 14L, 32L, 42L, 44L, 44L, 52L, 64L, 86L, 92L, 94L), 16L, 
          4L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 1L), 2L, 
          2L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(11L, 44L, 71L, 82L, 85L, 89L), 3L, 
          3L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -92L, -78L, -72L, -68L, -58L, -52L, -50L, -50L, -48L, -42L, -32L, -20L, -18L, -4L, 0L, 0L, 2L, 18L, 18L, 20L, 24L, 32L, 34L, 36L, 38L, 38L, 60L, 66L, 68L, 70L, 72L, 72L, 74L, 76L, 96L, 98L), 21L, 
          5L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 16L, 
          11L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(8L, 9L, 10L, 11L, 12L, 15L, 17L, 19L, 20L, 21L, 24L, 30L, 33L, 35L, 36L, 39L, 41L, 41L, 42L, 54L, 62L, 63L, 68L, 70L, 71L, 72L, 77L, 85L, 86L, 86L, 94L, 95L, 97L, 97L), 31L, 
          5L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-94L, -90L, -72L, -70L, -66L, -60L, -24L, -16L, 4L, 4L, 10L, 22L, 28L, 36L, 46L, 60L, 70L, 72L, 76L, 92L, 96L), 20L, 
          6L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 13L, 
          13L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(7L, 10L, 12L, 16L, 20L, 28L, 31L, 40L, 42L, 47L, 53L, 57L, 59L, 63L, 63L, 67L, 69L, 84L, 90L, 97L), 10L, 
          4L
      )))
  
  }
  
  main()
source_py: def maximum_removal_from_array_when_removal_time_waiting_time(arr, n):
      count = 0
      cummulative_sum = 0
      arr.sort()
      for i in range(n):
          if (arr[i] >= cummulative_sum):
              count += 1
              cummulative_sum += arr[i]
      return count
source_cpp: int maximum_removal_from_array_when_removal_time_waiting_time(vector<int> arr, int n) {
    int count = 0;
    int cummulative_sum = 0;
    sort(arr.begin(), arr.end());
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] >= cummulative_sum ) {
        count ++;
        cummulative_sum += arr [ i ];
      }
    }
    return count;
  }