Given Rupees. A liter plastic bottle of water costs Rupees and a litre of glass bottle of water costs Rupees. But the empty glass bottle after buying can be exchanged for Rupees. Find the maximum liters of water which can be bought with Rupees.
Input: N = 10 , A = 11 , B = 9 , C = 8
One glass bottle can be bought and then can be returned to buy one more glass bottle
Input: N = 15 , A = 6 , B = 4 , C = 3
Approach: If we have at least money then cost of one glass bottle is b – c. This means that if a ≤ (b – c) then we don’t need to buy glass bottles, only plastic ones, and the answer will be floor(n / a). Otherwise we need to buy glass bottles while we can.
So, if we have at least money, then we will buy floor((n – c) / (b – c)) glass bottles and then spend rest of the money on plastic ones.
Below is the implementation of the above approach:
- Maximum number of candies that can be bought
- Buy Maximum Stocks if i stocks can be bought on i-th day
- Water Connection Problem
- Trapping Rain Water
- Water drop problem
- Sliding Window Maximum (Maximum of all subarrays of size k) using stack in O(n) time
- Sliding Window Maximum (Maximum of all subarrays of size k)
- Maximum value of |arr[i] - arr[j]| + |i - j|
- Value in a given range with maximum XOR
- Maximum even sum subsequence
- Subsequence with maximum odd sum
- Maximum value of |arr - arr| + |arr - arr| + ... +|arr[n - 2] - arr[n - 1]| when elements are from 1 to n
- Maximum value of arr[i] % arr[j] for a given array
- Maximum Weight Difference
- Maximum Sum Decreasing Subsequence
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.