Choose K Numbers
Practice
1.8 (5 votes)
Binary search
Greedy algorithms
Medium
Open
Searching
Problem
27% Success 5353 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(Arr_i\) 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<=Arr_i<=10000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
AlgorithmsBinary Search
Points:30
13 votes
Tags:
AlgorithmsBinary SearchMediumSearchingpartitions
Points:30
4 votes
Tags:
AlgorithmsBinary Search