Maximize sum by selecting X different | Function to find maximum sum of at most N with different index array elements such that at most X are from A [ ] , Y are from B [ ] and Z are from C [ ] ; Base Cases ; Selecting i - th element from A [ ] ; Selecting i - th element from B [ ] ; Selecting i - th element from C [ ] ; i - th elements not selected from any of the arrays ; Select the maximum sum from all the possible calls ; Driver Code ; Given X , Y and Z ; Given A [ ] ; Given B [ ] ; Given C [ ] ; Given Size ; Function Call
def FindMaxS ( X , Y , Z , n ) : NEW_LINE INDENT global A , B , C NEW_LINE if ( X < 0 or Y < 0 or Z < 0 ) : NEW_LINE INDENT return - 10 ** 9 NEW_LINE DEDENT if ( n < 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 ) NEW_LINE ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 ) NEW_LINE co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 ) NEW_LINE no = FindMaxS ( X , Y , Z , n - 1 ) NEW_LINE maximum = max ( ch , max ( ca , max ( co , no ) ) ) NEW_LINE return maximum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = 1 NEW_LINE Y = 1 NEW_LINE Z = 1 NEW_LINE A = [ 10 , 0 , 5 ] NEW_LINE B = [ 5 , 10 , 0 ] NEW_LINE C = [ 0 , 5 , 10 ] NEW_LINE n = len ( B ) NEW_LINE print ( FindMaxS ( X , Y , Z , n - 1 ) ) NEW_LINE DEDENT