Given four positive integers A, B, C and K. The task is to check if it is possible to equalize the three integers A, B and C with the help of K and make K equal to 0. In one operation, you can subtract any value form K (if it remains greater than equal to 0 after subtraction) and add the new value to any of the three integers A, B or C.
Input: A = 6, B = 3, C = 2, K = 7
Operation 1: Add 3 to B and subtract 3 from K.
A = 6, B = 6, C = 2 and K = 4
Operation 2: Add 4 to C and subtract 4 from K.
A = 6, B = 6, C = 6 and K = 0
Input: A = 10, B = 20, C = 17, K = 15
Approach: Check whether it is possible to equalize the three numbers by sorting the three numbers and subtracting the value of K by the sum of the difference of 3rd and 2nd element and the 3rd and 1st element. If K is still greater than 0 and can be divided among the three elements equally then only the three elements can be made equal and K can be made equal to 0.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Minimum operations to make two numbers equal
- Minimum operations required to make two numbers equal
- Maximum count of equal numbers in an array after performing given operations
- Reach the numbers by making jumps of two given lengths
- Minimum increment operations to make K elements equal
- Minimum operations to make all elements equal using the second array
- Minimum operations to make frequency of all characters equal K
- Minimum operations of given type to make all elements of a matrix equal
- Minimum operations required to make all the array elements equal
- Minimum number of operations required to make two strings equal
- Minimum Cost to make all array elements equal using given operations
- Minimum decrement operations to make Array elements equal by only decreasing K each time
- Find the minimum number of operations required to make all array elements equal
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Print N distinct numbers following the given operations
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.