# Find minimum possible values of A, B and C when two of the (A + B), (A + C) and (B + C) are given

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.

**Examples:**

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:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find A, B and C ` `void` `MinimumValue(` `int` `x, ` `int` `y) ` `{ ` ` ` ` ` `// Keep minimum number in x ` ` ` `if` `(x > y) ` ` ` `swap(x, y); ` ` ` ` ` `// Find the numbers ` ` ` `int` `a = 1; ` ` ` `int` `b = x - 1; ` ` ` `int` `c = y - b; ` ` ` ` ` `cout << a << ` `" "` `<< b << ` `" "` `<< c; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `x = 123, y = 13; ` ` ` ` ` `// Function call ` ` ` `MinimumValue(x, y); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find A, B and C ` `static` `void` `MinimumValue(` `int` `x, ` `int` `y) ` `{ ` ` ` ` ` `// Keep minimum number in x ` ` ` `if` `(x > y) ` ` ` `{ ` ` ` `int` `temp = x; ` ` ` `x = y; ` ` ` `y = temp; ` ` ` `} ` ` ` ` ` `// Find the numbers ` ` ` `int` `a = ` `1` `; ` ` ` `int` `b = x - ` `1` `; ` ` ` `int` `c = y - b; ` ` ` ` ` `System.out.print( a + ` `" "` `+ b + ` `" "` `+ c); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `int` `x = ` `123` `, y = ` `13` `; ` ` ` ` ` `// Function call ` ` ` `MinimumValue(x, y); ` `} ` `} ` ` ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to find A, B and C ` `def` `MinimumValue(x, y): ` ` ` ` ` `# Keep minimum number in x ` ` ` `if` `(x > y): ` ` ` `x, y ` `=` `y, x ` ` ` ` ` `# Find the numbers ` ` ` `a ` `=` `1` ` ` `b ` `=` `x ` `-` `1` ` ` `c ` `=` `y ` `-` `b ` ` ` ` ` `print` `(a, b, c) ` ` ` `# Driver code ` `x ` `=` `123` `y ` `=` `13` ` ` `# Function call ` `MinimumValue(x, y) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find A, B and C ` `static` `void` `MinimumValue(` `int` `x, ` `int` `y) ` `{ ` ` ` ` ` `// Keep minimum number in x ` ` ` `if` `(x > y) ` ` ` `{ ` ` ` `int` `temp = x; ` ` ` `x = y; ` ` ` `y = temp; ` ` ` `} ` ` ` ` ` `// Find the numbers ` ` ` `int` `a = 1; ` ` ` `int` `b = x - 1; ` ` ` `int` `c = y - b; ` ` ` ` ` `Console.WriteLine( a + ` `" "` `+ b + ` `" "` `+ c); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main () ` `{ ` ` ` `int` `x = 123, y = 13; ` ` ` ` ` `// Function call ` ` ` `MinimumValue(x, y); ` `} ` `} ` ` ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

**Output:**

1 12 111

## Recommended Posts:

- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Maximum and Minimum Values of an Algebraic Expression
- Minimize the difference between the maximum and minimum values of the modified array
- Find smallest values of x and y such that ax - by = 0
- Find the values of X and Y in the Given Equations
- Find the sum of the ascii values of characters which are present at prime positions
- Find minimum x such that (x % k) * (x / k) == n | Set-2
- Find the value of N when F(N) = f(a)+f(b) where a+b is the minimum possible and a*b = N
- Find minimum x such that (x % k) * (x / k) == n
- Find minimum sum of factors of number
- Find minimum number of coins that make a given value
- Find the minimum number of steps to reach M from N
- Find minimum area of rectangle with given set of coordinates
- Find minimum speed to finish all Jobs
- Find the maximum possible value of the minimum value of modified array

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.