GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday 7 September 2022

[Solution] Mean and Median CodeChef Solution



Problem

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

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.


Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

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

If multiple answers exist, output any.

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.

No comments:

Post a Comment