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 bitwise OR of an array
- Maximize a value for a semicircle of given radius
- Maximize the total profit of all the persons
- Maximize the product of four factors of a Number
- Burst Balloon to maximize coins
- Maximize the happiness of the groups on the Trip
- Maximize the number of sum pairs which are divisible by K
- Remove an element to maximize the GCD of the given array
- Maximize the number of segments of length p, q and r
- Maximize volume of cuboid with given sum of sides
- Maximize profit when divisibility by two numbers have associated profits
- Maximize the sum of products of the degrees between any two vertices of the tree
- Number of ways to remove elements to maximize arithmetic mean
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.