Timer is Running

Adding Array Elements
Submissions: 5271   Accuracy:

7.65%

  Difficulty: Easy   Marks: 2

Given an array arr[] and an integer K, you have to Add the first two minimum elements of the array until all the elements are greater than or equal to K and find the number of such operations required. 

Examples:

Input : arr[] = {1 10 12 9 2 3}
          K = 6
Output : 2
First we add (1 + 2), now the new list becomes 
3 10 12 9 3, then we add (3 + 3),  now the new 
list becomes 6 10 12 9, Now all the elements in 
the list are greater than 6. Hence the output is 
2 i:e 2 operations are required 
to do this. 

Input :  The first line of input contains an integer T denoting the Test cases. Then T test cases follow.  Second line contains no. of array elements - N and K Third line array elements A[i] 

Output : 
Print number of operations required. If it is not possible to make elements greater than or equal to K, print "-1".

Constraints :
1 ≤ T ≤ 50
1 ≤ N, K ≤ 10^5
1 ≤ A[i] ≤ 10^6

Input : 
2
6 6
1 10 12 9 2 3
5 15
1 2 1 2 2

Output : 
2
-1

 

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

Contributor: Mohit Gupta_OMG :)
Author: Mohit Gupta 4


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.