Given integers n, a, b and c, the task is to find the maximum value of x + y + z such that ax + by + cz = n.
Input: n = 10, a = 5, b = 3, c = 4
x = 0, y = 2 and z = 1
Input: n = 50, a = 8, b = 10, c = 2
x = 0, y = 0 and z = 25
Approach: Fix the values of x and y then the value of z can be calculated as z = (n – (ax + by)) / c. If current value of z is an integer then update the maximum value of x + y + z found so far.
Below is the implementation of the above approach:
Time Complexity: O(N2)
- Maximize the value of the given expression
- Maximize the number of subarrays with XOR as zero
- Maximize a value for a semicircle of given radius
- Maximize the bitwise OR of an array
- Maximize the total profit of all the persons
- Maximize the product of four factors of a Number
- Burst Balloon to maximize coins
- Maximize the number of sum pairs which are divisible by K
- Maximize volume of cuboid with given sum of sides
- Maximize the number of segments of length p, q and r
- Maximize the sum of products of the degrees between any two vertices of the tree
- Maximize profit when divisibility by two numbers have associated profits
- Rearrange the string to maximize the number of palindromic substrings
- Maximize the maximum subarray sum after removing atmost one element
- Maximize the summation of numbers in a maximum of K moves in range [L, R]
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.