Given the range of cost from lowCost to upCost and range of quantity from lowQuant to upQuant, find if it is possible to get a given ration ratio r where , and lowCost <= cost <= upCost and lowQuant <= quantity <= upQuant.
Input : lowCost = 1, upCost = 10, lowQuant = 2, upQuant = 8 r = 3 Output : Yes Explanation: cost / quantity = 6 / 2 = 3 where cost is in [1, 10] and quantity is in [2, 8] Input : lowCost = 14, upCost = 30, lowQuant = 5, upQuant = 12 r = 9 Output : No
Approach: From the given formula, following equation can be easily deduced: . From this equation, logic can be easily deduced. Check the product of every value of quantity with r and if any value of the product lies between lowCost and upCost, then answer is Yes otherwise it is No.
Below is the implementation of above approach:
- Choose points from two ranges such that no point lies in both the ranges
- Program to find the common ratio of three numbers
- Find nth Fibonacci number using Golden ratio
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Program to find the count of coins of each type from the given ratio
- Find amount to be added to achieve target ratio in a given mixture
- Find speed of man from speed of stream and ratio of time with up and down streams
- Count Primes in Ranges
- P - smooth numbers in given ranges
- Queries for maximum difference between prime numbers in given ranges
- Print matrix after applying increment operations in M ranges
- Ratio of mth and nth term in an Arithmetic Progression (AP)
- Program to calculate the profit sharing ratio
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Section formula (Point that divides a line in given ratio)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t