[Solution] Mean and Median solution codechef

Mean and Median solution codechef – Chef has two numbers X and Y. Chef wants to find three integers A, B, and C such that:

  • -1000 \le A, B, C \le 1000
  • mean([A, B, C]) = X
  • median([A, B, C]) = Y

[Solution] Mean and Median solution codechef

Can you help Chef find such three integers?

As a reminder, mean([P, Q, R]) = \frac{P + Q + R}{3} and median([P, Q, R]) is the element at the 2^{nd} (middle) position after we sort [P, Q, R] in non-decreasing order.

Input Format

  • The first line contains a single integer T — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two space-separated integers X and Y — the required mean and median of the three integers.

Output Format

For each test case, output three integers A, B, C which satisfy the given conditions.

It is guaranteed that an answer always exists under the given constraints.

If multiple answers exist, output any.

Mean and Median solution codechef

  • 1 \leq T \leq 10^5
  • -100 \le X, Y \le 100

Sample 1:

Input

Output

3
5 5
67 100
4 5
5 5 5
0 100 101
0 5 7

Mean and Median solution codechef Explanation:

Test Case 1: mean([5, 5, 5]) = \frac{5 + 5 + 5}{3} = 5median([5, 5, 5]) = 5.

Test Case 2: mean([0, 100, 101]) = \frac{0 + 100 + 101}{3} = \frac{201}{3} = 67median([0, 100, 101]) = 100.

Test Case 3: mean([0, 5, 7]) = \frac{0 + 5 + 7}{3} = 4median([0, 5, 7]) = 5.

For Solution

“Click Here”

Leave a Comment