Timer is Running

Pair in array whose sum is closest to X
Submissions: 1187   Accuracy:


  Difficulty: Easy   Marks: 2

Given a sorted array and a number X, find a pair in array whose sum is closest to X.
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N and X denoting the size of array and value of X.
The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.

Print the pair whose sum is closest to X. If multiple pairs are possible print the largest sum pair.

1 <= T <= 100
2 <= N <= 100
0 <= X <= 500
0 =A[i]<=100

6 54
10 22 28 29 30 40
5 10
1 2 3 4 5
22 30
4 5

** For More Input/Output Examples Use 'Expected Output' option **

Author: vaibhav95

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.