Maximum profit by selling N items at two markets | Python3 implementation of the approach ; Max profit will be saved here ; loop to check all possible combinations of sales ; the sum of the profit after the sale for products 0 to i in market A ; the sum of the profit after the sale for products i to n in market B ; Replace the value of Max Profit with a bigger value among maxP and sumA + sumB ; Return the value of Max Profit ; Driver Program
def maxProfit ( a , b , n ) : NEW_LINE INDENT maxP = - 1 NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT sumA = sum ( a [ : i ] ) NEW_LINE sumB = sum ( b [ i : ] ) NEW_LINE maxP = max ( maxP , sumA + sumB ) NEW_LINE DEDENT return maxP NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 2 , 3 , 2 ] NEW_LINE b = [ 10 , 30 , 40 ] NEW_LINE print ( maxProfit ( a , b , 4 ) ) NEW_LINE DEDENT