Given two integers X and Y. X and Y represent any two values among (A + B), (A + C) and (B + C). The task is to find A, B and C such that A + B + C is minimum possible.
Input: X = 3, Y = 4
Output: 2 1 2
A = 2, B = 1, C = 2.
Then A + B = 3 and A + C = 4.
A + B + C = 5 which is minimum possible.
Input: X = 123, Y = 13
Output: 1 12 111
Approach: Let X = A + B and Y = B + C. If X > Y let’s swap them. Note that A + B + C = A + B + (Y – B) = A + Y. That’s why it’s optimal to minimize the value of A. So the value of A can always be 1. Then B = X – A and C = Y – B.
Below is the implementation of the above approach:
1 12 111
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- All possible values of floor(N/K) for all values of K
- Find two numbers with the given LCM and minimum possible difference
- Find minimum value of y for the given x values in Q queries from all the given set of lines
- Check if it is possible to make two martices strictly increasing by swapping corresponding values only
- Minimum LCM and GCD possible among all possible sub-arrays
- Minimum possible Bitwise OR of all Bitwise AND of pairs generated from two given arrays
- Minimum possible value T such that at most D Partitions of the Array having at most sum T is possible
- Sum of values of all possible non-empty subsets of the given array
- Product of values of all possible non-empty subsets of given Array
- Find two numbers with given sum and maximum possible LCM
- Minimum value possible of a given function from the given set
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Possible to form a triangle from array values
- Count of all possible values of X such that A % X = B
- Probability of getting all possible values on throwing N dices
- Possible values of Q such that, for any value of R, their product is equal to X times their sum
- Find the value of N when F(N) = f(a)+f(b) where a+b is the minimum possible and a*b = N
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B
- Find the values of X and Y in the Given Equations
- Find minimum possible digit sum after adding a number d
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.