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 the expression (A AND X) * (B AND X) | Bit Manipulation
- Maximize a value for a semicircle of given radius
- Maximize the bitwise OR of an array
- Maximize the Expression | Bit Manipulation
- Burst Balloon to maximize coins
- Maximize the product of four factors of a Number
- Maximize the number of sum pairs which are divisible by K
- Maximize the happiness of the groups on the Trip
- Remove an element to maximize the GCD of the given array
- Maximize volume of cuboid with given sum of sides
- Maximize the number of segments of length p, q and r
- Maximize the total profit of all the persons
- Maximize the number of palindromic Strings
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.