title: Maximum Removal From Array When Removal Time Waiting Time
signature: func maximumRemovalFromArrayWhenRemovalTimeWaitingTime(arr []int, n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{7, 33, 34, 42, 42, 45, 73}, 
  	5, 3)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 1}, 
  	2, 2)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{11, 44, 71, 82, 85, 89}, 
  	3, 3)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	16, 11)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{-94, -90, -72, -70, -66, -60, -24, -16, 4, 4, 10, 22, 28, 36, 46, 60, 70, 72, 76, 92, 96}, 
  	20, 6)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{7, 10, 12, 16, 20, 28, 31, 40, 42, 47, 53, 57, 59, 63, 63, 67, 69, 84, 90, 97}, 
  	10, 4)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }