title: Find Maximum Height Pyramid From The Given Array Of Objects
signature: function find_maximum_height_pyramid_from_the_given_array_of_objects(boxes, n)
test_code: using Printf
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  function validate_solution(actual, expected)
      return actual == expected
  end
  
  function driver(boxes, n, expected)
      try
  
          if validate_solution(PLACEHOLDER_FN_NAME(boxes, n), expected)
              return "PASSED";
          end
          return "FAILED";
      catch exception_obj
          return string(Base.typename(typeof(exception_obj)).wrapper);
      end
  end
  
  function main()
      
      result = driver([7, 8, 11, 11, 14, 19, 25, 27, 41, 42, 46, 52, 53, 54, 55, 58, 59, 62, 63, 66, 67, 69, 74, 75, 77, 81, 83, 84, 88, 88, 93, 93, 94], 22, 6);
      @printf("TEST-0...%s\n",result);
      
      result = driver([-96, -92, -78, -72, -60, -56, -28, -18, 12, 14, 16, 16, 20, 20, 30, 40, 72, 76, 76, 80, 86], 12, 1);
      @printf("TEST-1...%s\n",result);
      
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 35, 3);
      @printf("TEST-2...%s\n",result);
      
      result = driver([1, 4, 6, 12, 13, 14, 15, 16, 19, 21, 22, 27, 33, 37, 37, 40, 43, 45, 48, 50, 59, 63, 64, 65, 66, 67, 67, 67, 73, 78, 80, 81, 84, 85, 85, 91, 95, 95, 97, 98], 35, 7);
      @printf("TEST-3...%s\n",result);
      
      result = driver([-98, -92, -90, -88, -88, -74, -64, -64, -64, -62, -60, -52, -48, -46, -42, -42, -38, -34, -28, -26, -20, -20, -18, -4, 0, 2, 2, 6, 18, 18, 18, 20, 24, 24, 26, 32, 40, 46, 58, 66, 74, 78, 90, 96], 30, 1);
      @printf("TEST-4...%s\n",result);
      
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 21, 2);
      @printf("TEST-5...%s\n",result);
      
      result = driver([8, 12, 13, 13, 13, 16, 16, 17, 19, 20, 22, 23, 26, 29, 29, 30, 31, 37, 38, 39, 39, 41, 45, 45, 46, 49, 49, 53, 56, 62, 62, 66, 67, 68, 68, 69, 69, 73, 77, 78, 82, 85, 85, 88, 88, 97], 26, 6);
      @printf("TEST-6...%s\n",result);
      
      result = driver([-98, -98, -88, -84, -78, -76, -76, -74, -70, -68, -64, -62, -58, -44, -42, -38, -30, -28, -26, -24, -22, -20, -8, -6, 2, 4, 8, 8, 16, 18, 20, 34, 36, 40, 46, 60, 72, 78, 82, 82, 86, 90, 94, 94, 94], 25, 1);
      @printf("TEST-7...%s\n",result);
      
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 26, 2);
      @printf("TEST-8...%s\n",result);
      
      result = driver([3, 4, 21, 22, 23, 27, 27, 28, 28, 29, 30, 37, 39, 48, 50, 51, 54, 57, 61, 64, 64, 70, 71, 77, 85, 85, 88, 92, 93, 96, 97], 18, 5);
      @printf("TEST-9...%s\n",result);
      
  end
  
  main()
source_py: def find_maximum_height_pyramid_from_the_given_array_of_objects(boxes, n):
      boxes.sort()
      ans = 1
      prev_width = boxes[0]
      prev_count = 1
      curr_count = 0
      curr_width = 0
      for i in range(1, n):
          curr_width += boxes[i]
          curr_count += 1
          if ((curr_width > prev_width) and (curr_count > prev_count)):
              prev_width = curr_width
              prev_count = curr_count
              curr_count = 0
              curr_width = 0
              ans += 1
      return ans
source_cpp: int find_maximum_height_pyramid_from_the_given_array_of_objects(vector<int> boxes, int n) {
    sort(boxes.begin(), boxes.end());
    int ans = 1;
    int prev_width = boxes [ 0 ];
    int prev_count = 1;
    int curr_count = 0;
    int curr_width = 0;
    for ( int i = 1;
    i < n;
    i ++ ) {
      curr_width += boxes [ i ];
      curr_count += 1;
      if ( curr_width > prev_width && curr_count > prev_count ) {
        prev_width = curr_width;
        prev_count = curr_count;
        curr_count = 0;
        curr_width = 0;
        ans ++;
      }
    }
    return ans;
  }