title: Find Maximum Height Pyramid From The Given Array Of Objects
signature: find_maximum_height_pyramid_from_the_given_array_of_objects <- function(boxes, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(boxes, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(boxes, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(7L, 8L, 11L, 11L, 14L, 19L, 25L, 27L, 41L, 42L, 46L, 52L, 53L, 54L, 55L, 58L, 59L, 62L, 63L, 66L, 67L, 69L, 74L, 75L, 77L, 81L, 83L, 84L, 88L, 88L, 93L, 93L, 94L), 22L, 
          6L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-96L, -92L, -78L, -72L, -60L, -56L, -28L, -18L, 12L, 14L, 16L, 16L, 20L, 20L, 30L, 40L, 72L, 76L, 76L, 80L, 86L), 12L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 35L, 
          3L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(1L, 4L, 6L, 12L, 13L, 14L, 15L, 16L, 19L, 21L, 22L, 27L, 33L, 37L, 37L, 40L, 43L, 45L, 48L, 50L, 59L, 63L, 64L, 65L, 66L, 67L, 67L, 67L, 73L, 78L, 80L, 81L, 84L, 85L, 85L, 91L, 95L, 95L, 97L, 98L), 35L, 
          7L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -92L, -90L, -88L, -88L, -74L, -64L, -64L, -64L, -62L, -60L, -52L, -48L, -46L, -42L, -42L, -38L, -34L, -28L, -26L, -20L, -20L, -18L, -4L, 0L, 2L, 2L, 6L, 18L, 18L, 18L, 20L, 24L, 24L, 26L, 32L, 40L, 46L, 58L, 66L, 74L, 78L, 90L, 96L), 30L, 
          1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 
          2L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(8L, 12L, 13L, 13L, 13L, 16L, 16L, 17L, 19L, 20L, 22L, 23L, 26L, 29L, 29L, 30L, 31L, 37L, 38L, 39L, 39L, 41L, 45L, 45L, 46L, 49L, 49L, 53L, 56L, 62L, 62L, 66L, 67L, 68L, 68L, 69L, 69L, 73L, 77L, 78L, 82L, 85L, 85L, 88L, 88L, 97L), 26L, 
          6L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-98L, -98L, -88L, -84L, -78L, -76L, -76L, -74L, -70L, -68L, -64L, -62L, -58L, -44L, -42L, -38L, -30L, -28L, -26L, -24L, -22L, -20L, -8L, -6L, 2L, 4L, 8L, 8L, 16L, 18L, 20L, 34L, 36L, 40L, 46L, 60L, 72L, 78L, 82L, 82L, 86L, 90L, 94L, 94L, 94L), 25L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 26L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(3L, 4L, 21L, 22L, 23L, 27L, 27L, 28L, 28L, 29L, 30L, 37L, 39L, 48L, 50L, 51L, 54L, 57L, 61L, 64L, 64L, 70L, 71L, 77L, 85L, 85L, 88L, 92L, 93L, 96L, 97L), 18L, 
          5L
      )))
  
  }
  
  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;
  }