Check if all K | Function to check all subset - sums of K - length subsets in A [ ] is greater that that in the array B [ ] or not ; Sort the array in ascending order ; Sort the array in descending order ; Stores sum of first K elements of A [ ] ; Stores sum of first K elements of B [ ] ; Traverse both the arrays ; Update sum1 ; Update sum2 ; If sum1 exceeds sum2 ; Driver Code
def checkSubsetSum ( A , B , N , K ) : NEW_LINE INDENT A . sort ( ) NEW_LINE B . sort ( reverse = True ) NEW_LINE sum1 = 0 NEW_LINE sum2 = 0 NEW_LINE for i in range ( K ) : NEW_LINE INDENT sum1 += A [ i ] NEW_LINE sum2 += B [ i ] NEW_LINE DEDENT if ( sum1 > sum2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT A = [ 12 , 11 , 10 , 13 ] NEW_LINE B = [ 7 , 10 , 6 , 2 ] NEW_LINE N = len ( A ) NEW_LINE K = 3 NEW_LINE if ( checkSubsetSum ( A , B , N , K ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT