Choose K Numbers

1.8

5 votes
Binary Search, Greedy Algorithms, Medium, Open, Searching
Problem

You are given an array Arri of size N. You have to find the maximum value of K such that after choosing K numbers from the array the DiffValue of chosen numbers is less than or equal to S.

DiffValue for a set of integers is defined as the largest possible difference among any two integers of the set. However if you choose K numbers from the array, value of all the chosen numbers get multiplied by K.

Hence print two integers i.e the largest value of number K and largest possible DiffValue corresponding to value of K.

Input Format
First line contains T i.e number of testcases.
For each testcase,
First line contains two space separated integers denoting N and S and
The next line contains N space separated integers denoting the array.

Output Format
Print answer to each testcase in separate line.
For each testcase print two space separated integers denoting the value of K and DiffValue.

Constraints
1<=T<=100
1<=N<=50000
1<=S<=1000000000
1<=Arri<=10000

Sample Input
2
5 3
1 2 3 4 5
5 15
5 4 2 7 3
Sample Output
2 2
4 12
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For testcase 1 if we choose k=2 numbers i.e {1,2}. So the numbers get transformed into {1x2,2x2} = {2,4} giving the DiffValue=2 which is <= 3. Hence answer is 2 2.

Editor Image

?