Sunday, 28 November 2021

Three Pairwise Maximums Problem !!!

 PROBLEM 22: Three Pairwise Maximums


Problem Reference : Codeforces 

You are given three positive (i.e. strictly greater than zero) integers xy and z.

Your task is to find positive integers ab and c such that x=max(a,b)y=max(a,c) and z=max(b,c), or determine that it is impossible to find such ab and c.

You have to answer t independent test cases. Print required ab and c in any (arbitrary) order.


Input:

The first line of the input contains one integer t (1t2104) — the number of test cases. Then t test cases follow.

The only line of the test case contains three integers xy, and z (1x,y,z109).


Output:

For each test case, print the answer:

  • "NO" in the only line of the output if a solution doesn't exist;
  • or "YES" in the first line and any valid triple of positive integers ab and c (1a,b,c109) in the second line. You can print ab and c in any order.


Solution: 


  1. t = int(input())
  2. i = 0
  3. l = []
  4. while i < t :
  5. i = i + 1
  6. l = []
  7. x1,y1,z1 = input().split()
  8. x = int(x1)
  9. y = int(y1)
  10. z = int(z1)
  11. l.append(x)
  12. l.append(y)
  13. l.append(z)
  14. l.sort()
  15. if l[1] != l[2]:
  16. print("NO")
  17. else:
  18. print("YES")
  19. print(l[0],l[0],l[2])


The above solution is in python language.



Example
input
5
3 2 3
100 100 100
50 49 49
10 30 20
1 1000000000 1000000000
output
YES
3 2 1
YES
100 100 100
NO
NO
YES
1 1 1000000000

No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...