Maximum number of mangoes that can be bought | ''Function to check if mid number of mangoes can be bought ; '' Store the coins ; '' If watermelons needed are greater  than given watermelons ; '' Store remaining watermelons if vl  watermelons are used to buy mangoes ; '' Store the value of coins if these  watermelon get sold ; '' Increment coins by ex ; '' Number of mangoes that can be buyed  if only x coins needed for one mango ; '' If the condition is satisfied,  return true ; '' Otherwise return false ; ''Function to find the maximum number of mangoes that can be bought by selling watermelons ; '' Initialize the boundary values ; '' Store the required result ; '' Binary Search ; '' Store the mid value ; '' Check if it is possible to  buy mid number of mangoes ; '' Otherwise, update r to mid -1 ; '' Return the result ; ''Driver Code ; '' Given Input ; '' Function Call
def check ( n , m , x , y , vl ) : NEW_LINE INDENT temp = m NEW_LINE if ( vl > n ) : NEW_LINE INDENT return False NEW_LINE DEDENT ex = n - vl NEW_LINE ex *= y NEW_LINE temp += ex NEW_LINE cr = temp // x NEW_LINE if ( cr >= vl ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def maximizeMangoes ( n , m , x , y ) : NEW_LINE INDENT l = 0 NEW_LINE r = n NEW_LINE ans = 0 NEW_LINE while ( l <= r ) : NEW_LINE INDENT mid = l + ( r - l ) // 2 NEW_LINE if ( check ( n , m , x , y , mid ) ) : NEW_LINE INDENT ans = mid NEW_LINE l = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT r = mid - 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT W = 4 NEW_LINE C = 8 NEW_LINE x = 4 NEW_LINE y = 4 NEW_LINE print ( maximizeMangoes ( W , C , x , y ) ) NEW_LINE DEDENT