Maximize count of subsets having product of smallest element and size of the subset at least X | C # program to implement the above approach ; 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
using System ; using System . Linq ; class GFG { static int maxSubset ( int [ ] arr , int N , int X ) { Array . Sort ( arr ) ; Array . Reverse ( arr ) ; int counter = 0 ; int sz = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sz ++ ; if ( arr [ i ] * sz >= X ) { counter ++ ; sz = 0 ; } } return counter ; } public static void Main ( String [ ] args ) { int [ ] arr = { 7 , 11 , 2 , 9 , 5 } ; int N = arr . Length ; int X = 10 ; Console . Write ( maxSubset ( arr , N , X ) ) ; } }