Function to find the minimum number of elements in a sorted array A [ i . . j ] such that their sum is N
long long minimumSubsetSize ( vector < int > & A , int i , int j , int N ) { if ( ! N ) return 0 ; if ( i > j A [ i ] > N ) return INT_MAX ; if ( dp [ i ] [ N ] ) return dp [ i ] [ N ] ; dp [ i ] [ N ] = min ( 1 + minimumSubsetSize ( A , i + 1 , j , N - A [ i ] ) , minimumSubsetSize ( A , i + 1 , j , N ) ) ; return dp [ i ] [ N ] ; }