Maximize count of subsets having product of smallest element and size of the subset at least X | Function to return the maximum count of subsets possible which satisfy the above condition ; Sort the array in descending order ; Stores the count of subsets ; Stores the size of the current subset ; Check for the necessary conditions ; Driver Code
def maxSubset ( arr , N , X ) : NEW_LINE INDENT arr . sort ( reverse = True ) NEW_LINE counter = 0 NEW_LINE sz = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT sz += 1 NEW_LINE if ( arr [ i ] * sz >= X ) : NEW_LINE INDENT counter += 1 NEW_LINE sz = 0 NEW_LINE DEDENT DEDENT return counter NEW_LINE DEDENT arr = [ 7 , 11 , 2 , 9 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE X = 10 NEW_LINE print ( maxSubset ( arr , N , X ) ) NEW_LINE