Pair with largest sum which is less than K in the array
Submissions: 68   Accuracy: 14.7%   Difficulty: Easy   Marks: 2

Given an array arr of size N and an integer K. The task is to find the pair of integers in the array such that their sum is maximum but less than K

Input:
The first line of input contains an integer T denoting the number of test cases. T testcases follow.
The first line of each test case contains N and K, where N is the number of elements in the array and K is the bound. The second line of each test case contains the array elements.

Output:
Print the pair with the maximum sum less than K.

You don't have to take input. Complete the function Max_Sum(), which takes the array, N and K as parameters and returns the pair of integer if exist else return pair of zeros (0,0). The printing is done by the driver code.

Constraints:
1 ≤ T ≤ 10
0 ≤ N ≤ 105
0 ≤ K ≤ 106
0 ≤ arr[i] ≤ 105

Example:
Input:
2
6 10
2 3 4 6 8 10
6 0
2 3 4 6 8 10

Output:
3 6
0 0

Explanation:
Testcase 1: Pair (3,6) has a maximum sum equals 9 which is less than 10.
Testcase 2: There doesn't exist any pair in the array with a sum less than 0.

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

Contributor: Shivam Gupta
Author: xenon_shivam

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.