Count maximum number of consumable candies | Function to find the count of maximum consumable candies ; Store the count of total candies ; Stores the count of maximum consumable candies ; Checks if it is safe to counsume all candies ; Traverse the array arr ; If A [ i ] + M is greater than B [ i ] ; Mark all_safe as false ; Update ans ; Update ans ; Increment total by A [ i ] ; If all_safe is true ; Otherwise , ; Driver Code ; Function call to find maximum consumable candies
def maximumCandy ( candies , safety , N , M ) : NEW_LINE INDENT total = 0 NEW_LINE ans = 10 ** 8 NEW_LINE all_safe = True NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( candies [ i ] + M > safety [ i ] ) : NEW_LINE INDENT all_safe = False NEW_LINE ans = min ( ans , safety [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = min ( ans , candies [ i ] + M ) NEW_LINE DEDENT total += candies [ i ] NEW_LINE DEDENT if ( all_safe ) : NEW_LINE INDENT return total NEW_LINE DEDENT else : NEW_LINE INDENT return ans NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 4 , 5 , 2 , 3 ] NEW_LINE B = [ 8 , 13 , 6 , 4 ] NEW_LINE M = 5 NEW_LINE N = len ( A ) NEW_LINE print ( maximumCandy ( A , B , N , M ) ) NEW_LINE DEDENT