Given an array Arr[] of size N and an integer K, you have to choose the first two minimum elements of the array and erase them, then insert the sum of these two elements in the array until all the elements are greater than or equal to K and find the number of such operations required.
Example 1:
Input:
N = 6, K = 6 
Arr[] = {1, 10, 12, 9, 2, 3}
Output: 2
Explanation: 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. 
Example 2:
Input:
N = 4, K = 4
Arr[] = {5, 4, 6, 4}
Output: 0
Explanation: Every element in the given array 
is greater than or equal to K.
Your Task:
You don't need to read input or print anything. Your task is to complete the function minOperations() which takes array of integers arr, n and k as parameters and returns an integer denoting the answer. If it is not possible to make elements greater than or equal to K, return -1.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N)
Constraints :
1 ≤ N, K ≤ 10^{5}
1 ≤ Arr[i] ≤ 10^{6}

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N)

Starter code:


class Solution:

    def minOperations(self, arr, n, k):

        # code here



Solutions:
from heapq import *

class Solution:

	def minOperations(self, arr, n, k):
		minheap = []
		ans = 0
		for i in arr:
			heappush(minheap, i)
		while len(minheap) > 1:
			x = heappop(minheap)
			if x < k:
				y = heappop(minheap)
				heappush(minheap, x + y)
				ans += 1
			else:
				break
		temp = heappop(minheap)
		if temp < k:
			return -1
		return ans


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		op = 0
		if sum(arr) < k:
			return -1
		while len(arr) >= 2:
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			if a < k or b < k:
				s = a + b
				heapq.heappush(arr, s)
				op += 1
			else:
				return op
		return op


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		ans = 0
		if sum(arr) < k:
			return -1
		temp = arr.copy()
		heapq.heapify(temp)
		while temp[0] < k:
			(a, b) = (heapq.heappop(temp), heapq.heappop(temp))
			heapq.heappush(temp, a + b)
			ans += 1
		return ans


import heapq as hp

class Solution:

	def minOperations(self, arr, n, k):
		hp.heapify(arr)
		o = 0
		if sum(arr) < k:
			return -1
		while len(arr) >= 2:
			a = hp.heappop(arr)
			b = hp.heappop(arr)
			if a < k or b < k:
				hp.heappush(arr, a + b)
				o += 1
			else:
				return o
		return o


class Solution:

	def minOperations(self, arr, n, k):
		import heapq
		c = 0
		heap = arr.copy()
		heapq.heapify(heap)
		while heap[0] < k:
			if len(heap) < 2:
				return -1
			a = heapq.heappop(heap)
			b = heapq.heappop(heap)
			heapq.heappush(heap, a + b)
			c += 1
		return c


from heapq import heapify, heappush, heappop

class Solution:

	def minOperations(self, arr, n, k):
		heapify(arr)
		c = 0
		while arr[0] < k and len(arr) >= 2:
			temp = 0
			temp += heappop(arr)
			temp += heappop(arr)
			heappush(arr, temp)
			c += 1
		if arr[-1] >= k:
			return c
		return -1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heap = arr
		heapq.heapify(heap)
		x = 0
		num_op = 0
		while True:
			if heap == []:
				return -1
			x = heapq.heappop(heap)
			if x < k:
				if heap == []:
					return -1
				y = heapq.heappop(heap)
				heapq.heappush(heap, x + y)
				num_op += 1
			else:
				break
		return num_op


class Solution:

	def minOperations(self, arr, n, k):
		count = 0
		import heapq
		heapq.heapify(arr)
		while arr[0] < k:
			try:
				heapq.heappush(arr, heapq.heappop(arr) + heapq.heappop(arr))
			except IndexError:
				return -1
			count += 1
		return count


import heapq

class Solution:

	def lp(self, arr, k):
		for i in arr:
			if i < k:
				return -1
		return 1

	def minOperations(self, arr, n, k):
		c = 0
		heapq.heapify(arr)
		while self.lp(arr, k) != 1 and len(arr) > 1:
			data = heapq.heappop(arr) + heapq.heappop(arr)
			heapq.heappush(arr, data)
			c += 1
		if arr[0] >= k:
			return c
		else:
			return -1


from heapq import *

class Solution:

	def minOperations(self, arr, n, k):
		count = 0
		min_heap = []
		for i in arr:
			heappush(min_heap, i)
		if sum(min_heap) < k:
			return -1
		while len(min_heap) >= 2:
			temp1 = heappop(min_heap)
			temp2 = heappop(min_heap)
			if temp1 < k or temp2 < k:
				sum1 = temp1 + temp2
				heappush(min_heap, sum1)
				count += 1
			else:
				return count
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		if n == 1 and arr[0] != k:
			return -1
		heapq.heapify(arr)
		temp = heapq.heappop(arr)
		n -= 1
		count = 0
		flag = False
		while temp < k:
			count += 1
			n -= 1
			s = temp + heapq.heappop(arr)
			if n == 0 and s < k:
				flag = True
				break
			heapq.heappush(arr, s)
			temp = heapq.heappop(arr)
		if flag:
			return -1
		else:
			return count


class Solution:

	def minOperations(self, arr, n, K):
		import heapq
		heap = arr[:]
		heapq.heapify(heap)
		count = 0
		while heap[0] < K:
			if len(heap) < 2:
				return -1
			a = heapq.heappop(heap)
			b = heapq.heappop(heap)
			heapq.heappush(heap, a + b)
			count += 1
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		count = 0
		heapq.heapify(arr)
		while arr[0] < k and len(arr) >= 2:
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			heapq.heappush(arr, a + b)
			count += 1
		if len(arr) == 1 and arr[0] < k:
			return -1
		return count


class Solution:

	def minOperations(self, a, n, k):
		import heapq
		count = 0
		heapq.heapify(a)
		while a[0] < k and len(a) >= 2:
			x = heapq.heappop(a)
			y = heapq.heappop(a)
			heapq.heappush(a, x + y)
			count += 1
		if len(a) == 1 and a[0] < k:
			return -1
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		cnt = 0
		heapq.heapify(arr)
		while len(arr) > 1 and arr[0] < k:
			temp1 = heapq.heappop(arr)
			temp2 = heapq.heappop(arr)
			heapq.heappush(arr, temp1 + temp2)
			cnt += 1
		if arr[0] < k:
			return -1
		else:
			return cnt


class Solution:

	def minOperations(self, arr, n, k):
		import heapq
		heapq.heapify(arr)
		count = 0
		while len(arr) != 0:
			if arr[0] >= k:
				return count
			x = heapq.heappop(arr)
			if len(arr) == 0:
				return -1
			y = heapq.heappop(arr)
			heapq.heappush(arr, x + y)
			count += 1
		return -1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		count = 0
		while arr[0] < k and len(arr) > 1:
			item1 = heapq.heappop(arr)
			item2 = heapq.heappop(arr)
			heapq.heappush(arr, item1 + item2)
			count += 1
		return count if arr[0] >= k else -1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		c = 0
		if sum(arr) < k:
			return -1
		while len(arr) > 1:
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			if a < k or b < k:
				sum1 = a + b
				heapq.heappush(arr, sum1)
				c += 1
			else:
				return c
		return c


from heapq import *

class Solution:

	def minOperations(self, arr, n, k):
		heap = []
		for i in arr:
			heappush(heap, i)
		count = 0
		if sum(arr) < k:
			return -1
		while heap[0] < k and len(heap) > 1:
			if heap[0] < k:
				a = heappop(heap)
				b = heappop(heap)
				heappush(heap, a + b)
				count += 1
			else:
				break
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		code = True
		count = 0
		while code and len(arr) > 1:
			fst = heapq.heappop(arr)
			snd = heapq.heappop(arr)
			if fst >= k:
				return count
				code = False
			else:
				heapq.heappush(arr, fst + snd)
				count += 1
		if min(arr) >= k:
			return count
		return -1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		ctr = 0
		heapq.heapify(arr)
		mn = arr[0]
		while mn < k:
			if ctr == n - 1 and arr[0] < k:
				return -1
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			heapq.heappush(arr, a + b)
			ctr += 1
			mn = arr[0]
		return ctr


import heapq as hq

class Solution:

	def minOperations(self, arr, n, k):
		hq.heapify(arr)
		i = 0
		ans = 0
		while len(arr) > 1:
			if arr[0] < k:
				ele1 = hq.heappop(arr)
				ele2 = hq.heappop(arr)
				ans = ele1 + ele2
				hq.heappush(arr, ans)
				i += 1
			else:
				return i
		if ans >= k or arr[0] == k:
			return i
		return -1


class Solution:

	def minOperations(self, arr, n, k):
		import heapq
		arr_copy = list(arr)
		heapq.heapify(arr_copy)
		count = 0
		while len(arr_copy) >= 2:
			first = heapq.heappop(arr_copy)
			if first < k:
				second = heapq.heappop(arr_copy)
				heapq.heappush(arr_copy, first + second)
				count += 1
			else:
				return count
		last = heapq.heappop(arr_copy)
		if last < k:
			return -1
		else:
			return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		if n == 1 and arr[0] < k:
			return -1
		heapq.heapify(arr)
		res = 0
		cnt = 0
		flag = 0
		while arr[0] < k:
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			heapq.heappush(arr, a + b)
			if arr[0] < k and len(arr) == 1:
				flag = 1
				break
			cnt += 1
		if flag == 1:
			return -1
		else:
			return cnt


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		count = 0
		while arr[0] < k and len(arr) > 1:
			fir = heapq.heappop(arr)
			sec = heapq.heappop(arr)
			heapq.heappush(arr, fir + sec)
			count += 1
		if len(arr) == 1:
			if arr[0] >= k:
				return count
			else:
				return -1
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		if n == 0:
			return -1
		elif n == 1:
			if arr[0] >= k:
				return 0
			else:
				return -1
		else:
			heapq.heapify(arr)
			if arr[0] >= k:
				return 0
			opr = 0
			count = False
			while n > 1:
				m1 = heapq.heappop(arr)
				m2 = heapq.heappop(arr)
				heapq.heappush(arr, m1 + m2)
				opr += 1
				if arr[0] >= k:
					count = True
					break
				n -= 1
			if count == True:
				return opr
			else:
				return -1


from heapq import heapify, heappush, heappop

class Solution:

	def minOperations(self, arr, n, k):
		heapify(arr)
		min_val = heappop(arr)
		heappush(arr, min_val)
		if min_val >= k:
			count = 0
		else:
			count = 0
			while True:
				val = heappop(arr)
				if val >= k:
					break
				heappush(arr, val)
				if len(arr) == 1:
					count = -1
					break
				s = heappop(arr) + heappop(arr)
				heappush(arr, s)
				count += 1
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		count = 0
		flag = 0
		heapq.heapify(arr)
		while len(arr) > 1:
			if arr[0] >= k:
				break
			count += 1
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			heapq.heappush(arr, a + b)
		if arr[0] >= k:
			return count
		return -1


import heapq as hq

class Solution:

	def minOperations(self, arr, n, k):
		if sum(arr) < k:
			return -1
		q = []
		for i in arr:
			if i < k:
				hq.heappush(q, i)
		if len(q) <= 1:
			return len(q)
		else:
			cnt = 0
			while q != [] and len(q) > 1:
				cnt += 1
				(fm, sm) = (hq.heappop(q), hq.heappop(q))
				if fm + sm >= k:
					continue
				else:
					hq.heappush(q, fm + sm)
			return cnt + len(q)


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heap = []
		count = 0
		for i in arr:
			heapq.heappush(heap, i)
		while heap[0] < k and len(heap) >= 2:
			a = heapq.heappop(heap)
			b = heapq.heappop(heap)
			total = a + b
			heapq.heappush(heap, total)
			count = count + 1
		if len(heap) == 1 and heap[0] < k:
			return -1
		return count


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		o = 0
		heapq.heapify(arr)
		while len(arr) > 1 and arr[0] < k:
			n1 = heapq.heappop(arr)
			n2 = heapq.heappop(arr)
			heapq.heappush(arr, n1 + n2)
			o += 1
		if arr[0] >= k:
			return o
		return -1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		ops = 0
		while True:
			if arr[0] >= k:
				return ops
			else:
				if len(arr) == 1 and arr[0] < k:
					return -1
				a = heapq.heappop(arr)
				b = heapq.heappop(arr)
				heapq.heappush(arr, a + b)
				ops += 1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		ope = 0
		heapq.heapify(arr)
		x = heapq.nsmallest(1, arr)
		while arr[0] < k:
			if len(arr) == 1:
				if arr[0] < k:
					return -1
			a = heapq.heappop(arr)
			b = heapq.heappop(arr)
			heapq.heappush(arr, a + b)
			ope += 1
		return ope


from heapq import *

class Solution:

	def minOperations(self, arr, n, k):
		if sum(arr) < k:
			return -1
		heap = []
		for elements in arr:
			heappush(heap, elements)
		ans = 0
		while heap:
			if len(heap) == 1:
				if heap[0] >= k:
					return ans
				else:
					return -1
			v1 = heappop(heap)
			v2 = heappop(heap)
			if v1 >= k and v2 >= k:
				break
			heappush(heap, v1 + v2)
			ans += 1
		return ans


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		temp = 0
		heapq.heapify(arr)
		while len(arr) > 1:
			p = heapq.heappop(arr)
			q = heapq.heappop(arr)
			if p >= k:
				return temp
			else:
				heapq.heappush(arr, p + q)
				temp += 1
		if arr[0] < k:
			return -1
		return temp


class Solution:

	def minOperations(self, arr, n, k):
		import heapq
		heap = []
		for item in arr:
			heapq.heappush(heap, item)
		first = heapq.heappop(heap)
		if first >= k:
			return 0
		elif len(heap) == 0:
			return -1
		second = heapq.heappop(heap)
		heapq.heappush(heap, first + second)
		count = 1
		while len(heap) > 1:
			first = heapq.heappop(heap)
			if first >= k:
				return count
			else:
				second = heapq.heappop(heap)
				heapq.heappush(heap, first + second)
			count += 1
		if heapq.heappop(heap) >= k:
			return count
		return -1


class Solution:

	def minOperations(self, arr, n, k):
		count = 0
		l = [0] * (k + 1)
		firstminimumnumber = -1
		secondminimumnumber = -1
		for i in range(n):
			if arr[i] >= k:
				l[k] = 1
			else:
				l[arr[i]] += 1
		for i in range(len(l)):
			for j in range(l[i]):
				if firstminimumnumber == -1:
					firstminimumnumber = i
				elif secondminimumnumber == -1:
					secondminimumnumber = i
					if firstminimumnumber + secondminimumnumber >= k:
						l[k] = 1
					else:
						l[firstminimumnumber + secondminimumnumber] += 1
					count += 1
					firstminimumnumber = -1
					secondminimumnumber = -1
		if l[k] == 0:
			return -1
		else:
			return count


from heapq import heappush, heappop, heapify

class Solution:

	def minOperations(self, arr, n, k):
		heapify(arr)
		ans = 0
		while arr[0] < k and len(arr) > 1:
			x1 = heappop(arr)
			x2 = heappop(arr)
			heappush(arr, x1 + x2)
			ans += 1
		return -1 if arr[0] < k else ans


class Solution:

	def minOperations(self, arr, n, k):
		import heapq
		heapq.heapify(arr)
		cnt = 0
		while arr[0] < k:
			if len(arr) >= 2:
				a = heapq.heappop(arr)
				b = heapq.heappop(arr)
				heapq.heappush(arr, a + b)
				cnt += 1
			else:
				return -1
		return cnt


from heapq import heapify, heappop, heappush

class Solution:

	def minOperations(self, arr, n, k):
		heapify(arr)
		c = 0
		while arr[0] < k and len(arr) > 1:
			a = heappop(arr)
			b = heappop(arr)
			heappush(arr, a + b)
			c += 1
		if len(arr) == 1 and arr[0] < k:
			return -1
		return c


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		cnt = 0
		if self.check(arr, k):
			return cnt
		else:
			heapq.heapify(arr)
			for i in range(len(arr)):
				if len(arr) < 2 and sum(arr) < k:
					return -1
				(a, b) = (heapq.heappop(arr), heapq.heappop(arr))
				newele = a + b
				heapq.heappush(arr, newele)
				cnt += 1
				if self.check(arr, k):
					break
			return cnt

	def check(self, arr, k):
		for i in range(len(arr)):
			if arr[i] < k:
				return False
		return True


from heapq import heapify, heappop, heappush

class Solution:

	def minOperations(self, arr, n, k):
		heapify(arr)
		c = 0
		for i in range(n - 1):
			a = heappop(arr)
			if a >= k:
				return c
			b = heappop(arr)
			heappush(arr, a + b)
			c += 1
		a = heappop(arr)
		if a >= k:
			return c
		return -1


from collections import deque
import heapq

class Solution:

	def lp(self, arr, k):
		for i in arr:
			if i < k:
				return -1
		return 1

	def minOperations(self, arr, n, k):
		c = 0
		heapq.heapify(arr)
		while self.lp(arr, k) != 1 and len(arr) > 1:
			data = heapq.heappop(arr) + heapq.heappop(arr)
			heapq.heappush(arr, data)
			c += 1
		if arr[0] >= k:
			return c
		else:
			return -1
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq as h

class Solution:

	def minOperations(self, arr, n, k):
		a = []
		for i in arr:
			h.heappush(a, i)
		cnt = 0
		ans = h.heappop(a)
		while ans < k and len(a) >= 1:
			cnt += 1
			l = h.heappop(a)
			res = l + ans
			h.heappush(a, res)
			ans = h.heappop(a)
		if ans < k:
			return -1
		return cnt
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq as hq

class Solution:

	def minOperations(self, arr, n, k):
		if sum(arr) < k:
			return -1
		q = []
		for i in arr:
			if i < k:
				hq.heappush(q, i)
		if len(q) <= 1:
			return len(q)
		else:
			c = 0
			while q != [] and len(q) > 1:
				c += 1
				(f, se) = (hq.heappop(q), hq.heappop(q))
				s = f + se
				if s >= k:
					continue
				else:
					hq.heappush(q, s)
			return c + len(q)
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq as hq

class Solution:

	def minOperations(self, arr, n, k):
		if sum(arr) < k:
			return -1
		q = []
		for i in arr:
			if i < k:
				hq.heappush(q, i)
		if len(q) <= 1:
			return len(q)
		else:
			cnt = 0
			while q != [] and len(q) > 1:
				cnt += 1
				(fm, sm) = (hq.heappop(q), hq.heappop(q))
				if fm + sm >= k:
					continue
				else:
					hq.heappush(q, fm + sm)
			return cnt + len(q)
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		c = 0
		while len(arr) != 1:
			a = heapq.heappop(arr)
			if a >= k:
				return c
			b = heapq.heappop(arr)
			heapq.heappush(arr, a + b)
			c += 1
		return c if heapq.heappop(arr) >= k else -1
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		if n == 1 and arr[0] != k:
			return -1
		heapq.heapify(arr)
		temp = heapq.heappop(arr)
		n -= 1
		count = 0
		flag = False
		while temp < k:
			count += 1
			n -= 1
			s = temp + heapq.heappop(arr)
			if n == 0 and s < k:
				flag = True
				break
			heapq.heappush(arr, s)
			temp = heapq.heappop(arr)
		if flag:
			return -1
		else:
			return count
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq as h

class Solution:

	def minOperations(self, arr, n, k):
		mh = []
		for i in arr:
			h.heappush(mh, i)
		nop = 0
		while True:
			if mh[0] < k:
				nop += 1
				el = None
				el2 = None
				if mh:
					el = h.heappop(mh)
				if mh:
					el2 = h.heappop(mh)
				if el == None or el2 == None:
					return -1
				h.heappush(mh, el + el2)
			else:
				break
		return nop
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		if arr == []:
			return -1
		op = 0
		heapq.heapify(arr)
		flag = True
		while flag and len(arr) > 0:
			minele1 = heapq.heappop(arr)
			if minele1 >= k:
				return op
				flag = False
			if len(arr) > 0:
				minele2 = heapq.heappop(arr)
				ele = minele1 + minele2
				op += 1
				heapq.heappush(arr, ele)
		return -1
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1


import heapq

class Solution:

	def minOperations(self, arr, n, k):
		heapq.heapify(arr)
		code = True
		count = 0
		while code and len(arr) > 1:
			fst = heapq.heappop(arr)
			snd = heapq.heappop(arr)
			if fst >= k:
				return count
				code = False
			else:
				heapq.heappush(arr, fst + snd)
				count += 1
		if min(arr) >= k:
			return count
		return -1
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		ans = Solution().minOperations(arr, n, k)
		print(ans)
		tc -= 1