Maximum Tip Calculator | Recursive function to calculate sum of maximum tip order taken by X and Y ; When all orders have been taken ; When X cannot take more orders ; When Y cannot take more orders ; When both can take order calculate maximum out of two ; Driver code
def solve ( i , X , Y , a , b , n ) : NEW_LINE INDENT if ( i == n ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( X <= 0 ) : NEW_LINE INDENT return ( b [ i ] + solve ( i + 1 , X , Y - 1 , a , b , n ) ) NEW_LINE DEDENT if ( Y <= 0 ) : NEW_LINE INDENT return ( a [ i ] + solve ( i + 1 , X - 1 , Y , a , b , n ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return max ( a [ i ] + solve ( i + 1 , X - 1 , Y , a , b , n ) , b [ i ] + solve ( i + 1 , X , Y - 1 , a , b , n ) ) NEW_LINE DEDENT DEDENT a = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE b = [ 5 , 4 , 3 , 2 , 1 ] NEW_LINE n = len ( a ) NEW_LINE x = 3 NEW_LINE y = 3 NEW_LINE print ( solve ( 0 , x , y , a , b , n ) ) NEW_LINE