title: Maximum Removal From Array When Removal Time Waiting Time
signature: maximumRemovalFromArrayWhenRemovalTimeWaitingTime :: [Integer] -> Integer -> Integer
  maximumRemovalFromArrayWhenRemovalTimeWaitingTime arr n = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Integer -> Integer -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Integer -> String
  driver arr n expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr n) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([7, 33, 34, 42, 42, 45, 73]) (5) (3) )
  
      printf "TEST-1...%s\n" (driver ([-98, -90, -80, -66, -64, -62, -48, -30, -20, -10, 4, 6, 12, 14, 32, 42, 44, 44, 52, 64, 86, 92, 94]) (16) (4) )
  
      printf "TEST-2...%s\n" (driver ([0, 0, 0, 0, 1]) (2) (2) )
  
      printf "TEST-3...%s\n" (driver ([11, 44, 71, 82, 85, 89]) (3) (3) )
  
      printf "TEST-4...%s\n" (driver ([-96, -92, -78, -72, -68, -58, -52, -50, -50, -48, -42, -32, -20, -18, -4, 0, 0, 2, 18, 18, 20, 24, 32, 34, 36, 38, 38, 60, 66, 68, 70, 72, 72, 74, 76, 96, 98]) (21) (5) )
  
      printf "TEST-5...%s\n" (driver ([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) (16) (11) )
  
      printf "TEST-6...%s\n" (driver ([8, 9, 10, 11, 12, 15, 17, 19, 20, 21, 24, 30, 33, 35, 36, 39, 41, 41, 42, 54, 62, 63, 68, 70, 71, 72, 77, 85, 86, 86, 94, 95, 97, 97]) (31) (5) )
  
      printf "TEST-7...%s\n" (driver ([-94, -90, -72, -70, -66, -60, -24, -16, 4, 4, 10, 22, 28, 36, 46, 60, 70, 72, 76, 92, 96]) (20) (6) )
  
      printf "TEST-8...%s\n" (driver ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) (13) (13) )
  
      printf "TEST-9...%s\n" (driver ([7, 10, 12, 16, 20, 28, 31, 40, 42, 47, 53, 57, 59, 63, 63, 67, 69, 84, 90, 97]) (10) (4) )
  
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;
  }