One day, Ahmed_Hossam went to Hemose and said "Let's solve a gym contest!". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him?

There is an Agent in Valorant, and he has $n$ weapons. The $i$-th weapon has a damage value $a_i$, and the Agent will face an enemy whose health value is $H$.

The Agent will perform one or more moves until the enemy dies.

In one move, he will choose a weapon and decrease the enemy's health by its damage value. The enemy will die when his health will become less than or equal to $0$. However, not everything is so easy: the Agent can't choose the same weapon for $2$ times in a row.

What is the minimum number of times that the Agent will need to use the weapons to kill the enemy?


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ $(1 \leq t \leq 10^5)$. Description of the test cases follows.

The first line of each test case contains two integers $n$ and $H$ $(2 \leq n \leq 10^3, 1 \leq H \leq 10^9)$ — the number of available weapons and the initial health value of the enemy.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 10^9)$ — the damage values of the weapons.

It's guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print a single integer — the minimum number of times that the Agent will have to use the weapons to kill the enemy.


-----Examples-----

Input
3
2 4
3 7
2 6
4 2
3 11
2 1 7
Output
1
2
3


-----Note-----

In the first test case, the Agent can use the second weapon, making health value of the enemy equal to $4-7=-3$. $-3 \le 0$, so the enemy is dead, and using weapon $1$ time was enough.

In the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of enemy will drop to $6-4-2 = 0$, meaning he would be killed after using weapons $2$ times.

In the third test case, the Agent can use the weapons in order (third, first, third), decreasing the health value of enemy to $11 - 7 - 2 - 7 = -5$ after using the weapons $3$ times. Note that we can't kill the enemy by using the third weapon twice, as even though $11-7-7<0$, it's not allowed to use the same weapon twice in a row.

Difficulty: EASY
Tags: Sorting

Mathematics

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
from sys import stdin
input = stdin.readline
for i in range(int(input())):
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	a = arr[-1]
	b = arr[-2]
	ans = h // (a + b) * 2
	if h % (a + b) > a:
		ans += 2
	elif h % (a + b) == 0:
		ans += 0
	else:
		ans += 1
	print(ans)


from sys import stdin

def solve():
	results = []
	for _ in range(int(stdin.readline().strip())):
		(N, H) = map(int, stdin.readline().strip().split())
		A = sorted(list(map(int, stdin.readline().strip().split())), reverse=True)
		if A[0] >= H:
			results.append(1)
			continue
		maxtwo = A[0] + A[1]
		c = H // maxtwo
		h = c * maxtwo
		c *= 2
		i = 0
		while h < H:
			h += A[i]
			i = (i + 1) % 2
			c += 1
		results.append(c)
	print('\n'.join((str(x) for x in results)))
solve()


import sys
input = sys.stdin.readline
rep = int(input())
for _ in range(rep):
	(a, b) = map(int, input().split())
	data = list(map(int, input().split()))
	data.sort(reverse=True)
	(c, d) = (data[0], data[1])
	if b <= c:
		print(1)
		continue
	result = 0
	result += b // (c + d) * 2
	p = (c + d) * (result // 2)
	if p >= b:
		print(result)
	elif p + c >= b:
		print(result + 1)
	else:
		print(result + 2)


import sys
read = sys.stdin.readline
for i in range(int(read())):
	(n, H) = map(int, read().split())
	arr = list(reversed(sorted(list(map(int, read().split())))))
	if arr[0] > H:
		print(1)
		continue
	temp = arr[0] + arr[1]
	req = H - H % temp
	ans = req // temp * 2
	if req == H:
		print(ans)
	elif req + arr[0] >= H:
		print(ans + 1)
	else:
		print(ans + 2)


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	(n, H) = [int(j) for j in stdin.readline().split()]
	A = [int(j) for j in stdin.readline().split()]
	A.sort()
	max1 = A[-1]
	max2 = A[-2]
	f = True
	min = H // (max1 + max2) * 2
	H %= max1 + max2
	while H > 0:
		if f:
			H -= max1
			f = not f
		else:
			H -= max2
			f = not f
		min += 1
	print(min)


def getlistint():
	return list(map(int, stdin.readline().split()))

def getmapint():
	return map(int, stdin.readline().split())

def getliststr():
	return list(stdin.readline().split())

def getint():
	return int(stdin.readline().strip())

def getstr():
	return stdin.readline().strip()

def pr(s):
	stdout.write(str(s) + '\n')

def prlist(l):
	stdout.write(' '.join(list(map(str, l))) + '\n')
from sys import stdin, stdout
for _ in range(getint()):
	(n, h) = getmapint()
	a = getlistint()
	m1 = a.pop(a.index(max(a)))
	m2 = a.pop(a.index(max(a)))
	i = h // (m1 + m2)
	if h - m1 <= 0:
		pr(1)
	elif h % (m1 + m2) == 0:
		pr(i * 2)
	else:
		h -= (m1 + m2) * i
		if h - m1 <= 0:
			pr(i * 2 + 1)
		else:
			pr(i * 2 + 2)


import math
from sys import stdin
input = stdin.readline
test = int(input())
for _ in range(test):
	(n, H) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n == 1:
		print(math.ceil(H / n))
	arr = sorted(arr, reverse=True)
	(a, b) = (arr[0], arr[1])
	(res, H) = (2 * (H // (a + b)), H % (a + b))
	if H > a:
		res += 2
	elif H > 0:
		res += 1
	print(res)


from sys import stdin
import math

def read_input():
	(n, H) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	return (n, H, a)

def solve(n, H, a):
	a.sort(reverse=True)
	x = a[0]
	y = a[1]
	m = math.ceil(H / (x + y))
	if (m - 1) * (x + y) + x >= H:
		return 2 * m - 1
	else:
		return 2 * m

def main():
	t = int(stdin.readline())
	for _ in range(t):
		input = read_input()
		answer = solve(*input)
		print(answer)
main()


import sys
import math
from bisect import bisect_right as br
from itertools import combinations as cb

def int_arr():
	return list(map(int, sys.stdin.readline().strip().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, h) = int_arr()
	arr = int_arr()
	arr.sort()
	arr.reverse()
	mx = arr[0]
	mx2 = arr[1]
	tot = mx + mx2
	rem = h % tot
	if rem == 0:
		print(h // tot * 2)
	else:
		rem -= mx
		if rem <= 0:
			print(h // tot * 2 + 1)
			continue
		rem -= mx2
		if rem <= 0:
			print(h // tot * 2 + 2)
			continue


import sys
t = int(sys.stdin.readline())
while t > 0:
	t -= 1
	n = sys.stdin.readline().split()
	(n1, h) = (int(n[0]), int(n[1]))
	guns = sys.stdin.readline().split()
	guns = [int(i) for i in guns]
	guns = sorted(guns, reverse=True)
	ans = h // (guns[0] + guns[1])
	h = h - ans * (guns[0] + guns[1])
	i = ans * 2
	if h > 0:
		if h > guns[0]:
			i += 2
		else:
			i += 1
	print(i)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, h) = list(map(int, stdin.readline().split()))
	a = sorted(map(int, stdin.readline().split()), reverse=True)
	b = a[0] + a[1]
	(c, d) = divmod(h, b)
	res = c * 2 + (d > 0)
	if d > a[0]:
		res += 1
	print(res)


import sys
input = sys.stdin.readline

def solve():
	(n, H) = map(int, input().split())
	(*a,) = map(int, input().split())
	a.sort()
	(a, b) = (a[-1], a[-2])
	print(min((H + (a + b - 1)) // (a + b) * 2, 1 + (H - a + (a + b - 1)) // (a + b) * 2))
for i in range(int(input())):
	solve()


from math import ceil
from sys import stdin
input = stdin.readline

def func():
	(a1, a2) = (a[0], a[1])
	k = ceil(h / (a1 + a2))
	if h + a2 - k * (a1 + a2) <= 0:
		print(2 * k - 1)
	elif h - k * (a1 + a2) <= 0:
		print(2 * k)
	else:
		print(2 * k + 1)
for _ in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	func()


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
while t > 0:
	(n, h) = invr()
	a = inlt()
	a.sort()
	(x, y) = (a[len(a) - 1], a[len(a) - 2])
	if h % (x + y) == 0:
		print(int(2 * (h / (x + y))))
	elif h % (x + y) <= x:
		print(2 * math.floor(h / (x + y)) + 1)
	else:
		print(2 * math.floor(h / (x + y)) + 2)
	t = t - 1


from sys import stdin, exit, setrecursionlimit
from collections import deque
from heapq import *
from math import gcd
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	(n, h) = mi()
	arr = sorted(lmi())[::-1]
	tmp = h // (arr[0] + arr[1])
	h -= tmp * (arr[0] + arr[1])
	ans = tmp * 2
	if h > 0:
		h -= arr[0]
		ans += 1
		if h > 0:
			h -= arr[1]
			ans += 1
	print(ans)


from math import ceil

def solve(n, h, weapons):
	weapons.sort(reverse=True)
	max1 = weapons[0]
	max2 = weapons[1]
	s = max1 + max2
	ans = h // s
	if h % s == 0:
		return ans * 2
	rem = h % s
	if rem > max1:
		return ans * 2 + 2
	return ans * 2 + 1
t = int(input().strip())
inputs = []
for _ in range(t):
	(n, h) = map(int, input().strip().split())
	weapons = list(map(int, input().strip().split()))
	inputs.append((n, h, weapons))
for (n, h, weapons) in inputs:
	print(solve(n, h, weapons))


import sys
input = lambda : sys.stdin.readline()[:-1]
ni = lambda : int(input())
na = lambda : list(map(int, input().split()))
sys.setrecursionlimit(10 ** 7)
yes = lambda : print('yes')
Yes = lambda : print('Yes')
YES = lambda : print('YES')
no = lambda : print('no')
No = lambda : print('No')
NO = lambda : print('NO')
t = ni()
for _ in range(t):
	(n, h) = na()
	a = na()
	a = sorted(a)
	(m1, m2) = (a[-1], a[-2])
	ans = min((h - m1 + m1 + m2 - 1) // (m1 + m2) * 2 + 1, (h + m1 + m2 - 1) // (m1 + m2) * 2)
	print(ans)


t = int(input())
ans_mas = []
for i in range(t):
	(n, H) = map(int, input().split())
	a = list(map(int, input().split()))
	max_1 = max(a)
	a.remove(max_1)
	max_2 = max(a)
	ost = H % (max_1 + max_2)
	if ost == 0:
		ans = 2 * (H // (max_1 + max_2))
	else:
		l = H // (max_1 + max_2)
		if H - l * (max_1 + max_2) > 0:
			if H - l * (max_1 + max_2) - max_1 <= 0:
				ans = 2 * l + 1
			else:
				ans = 2 * (l + 1)
		elif H - l * (max_1 + max_2) + max_2 > 0:
			ans = 2 * l - 1
		else:
			ans = 2 * l - 2
	ans_mas.append(ans)
print(*ans_mas, sep='\n')


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 10 ** 16
md = 998244353

def solve():
	(n, h) = LI()
	aa = LI()
	aa.sort()
	a = aa[-1]
	b = aa[-2]
	(q, r) = divmod(h, a + b)
	ans = q * 2
	h -= q * (a + b)
	if h == 0:
		print(ans)
	elif h <= a:
		print(ans + 1)
	else:
		print(ans + 2)
for testcase in range(II()):
	solve()


import math
import heapq
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	(n, h) = M()
	l = L()
	a = max(l)
	l.pop(l.index(a))
	b = max(l)
	t = h // (a + b) * 2
	p = h % (a + b)
	if p > 0:
		t += 1
		if p > a:
			t += 1
	print(t)


k = []
t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if h < max(a):
		k.append(1)
	else:
		r = a[-1] + a[-2]
		if h % r == 0:
			k.append(2 * (h // r))
		elif h // r * r + a[-1] < h:
			k.append(2 * (h // r) + 2)
		else:
			k.append(2 * (h // r) + 1)
for i in k:
	print(i)


def max_2(list):
	list.sort()
	maximum = list[-1]
	maximum_2nd = list[-2]
	return (maximum, maximum_2nd)

def number_of_times(list, health):
	(maximum, maximum_2nd) = max_2(list)
	y = health % (maximum + maximum_2nd)
	z = int(health / (maximum + maximum_2nd)) * 2
	if y == 0:
		number = z
	else:
		p = z / 2 * (maximum + maximum_2nd) + maximum
		if p >= health:
			number = z + 1
		else:
			number = z + 2
	return number
t = int(input())
weapon_list_2D = []
health_list = []
for test_case in range(t):
	(n, H) = input().split()
	n = int(n)
	H = int(H)
	health_list.append(H)
	weapon_list = input().split()
	for i in range(len(weapon_list)):
		weapon_list[i] = int(weapon_list[i])
	weapon_list_2D.append(weapon_list)
for i in range(len(weapon_list_2D)):
	list = weapon_list_2D[i]
	health = health_list[i]
	number = number_of_times(list, health)
	print(number)


def func(H, weapons):
	weapons = sorted(weapons, reverse=True)
	temp = weapons[0] + weapons[1]
	shot = int(H / temp)
	if shot * temp + weapons[0] < H:
		return shot * 2 + 2
	elif shot * temp == H:
		return shot * 2
	else:
		return shot * 2 + 1
	return 0
cases = int(input())
out = []
for _ in range(cases):
	temp = [int(i) for i in input().split(' ')]
	n = temp[0]
	H = temp[1]
	temp = [int(i) for i in input().split(' ')]
	temp += [0, 0]
	out.append(func(H, temp))
for item in out:
	print(item)


tc = int(input())
ans = []
for i in range(tc):
	input_string = input()
	n = input_string.split()
	temp = input()
	weapons = temp.split()
	for i in range(int(n[0])):
		weapons[i] = int(weapons[i])
	weapons.sort(reverse=True)
	if int(n[0]) == 1:
		mustUse = int(int(n[1]) / weapons[0])
		rem = int(n[1]) - mustUse / 2 * weapons[0]
		if rem > 0:
			mustUse += 1
		ans.append(mustUse)
		continue
	totalPower = weapons[0] + weapons[1]
	mustUse = int(int(n[1]) / totalPower) * 2
	rem = int(n[1]) - mustUse / 2 * totalPower
	if rem > weapons[0]:
		mustUse = mustUse + 2
	elif rem <= weapons[0] and rem != 0:
		mustUse = mustUse + 1
	ans.append(mustUse)
for i in ans:
	print(i)


for _ in range(int(input())):
	(n, H) = map(int, input().split())
	A = [int(a) for a in input().split()]
	A.sort()
	(a, b) = (A[-1], A[-2])
	k = H // (a + b) * 2
	H %= a + b
	if H == 0:
		print(k)
	elif H <= a:
		print(k + 1)
	else:
		print(k + 2)


t = int(input())
for _ in range(t):
	(n, H) = map(int, input().split())
	weapons = sorted(list(map(int, input().split())))
	ans = H // (weapons[-1] + weapons[-2]) * 2
	H %= weapons[-1] + weapons[-2]
	if H > 0:
		if H > weapons[-1]:
			ans += 2
		else:
			ans += 1
	print(ans)


for i in range(int(input())):
	(n, h) = map(int, input().split())
	A = [int(k) for k in input().split()]
	A.sort()
	a = 0
	l = A[-1] + A[-2]
	j = h // l
	o = h % l
	if o == 0:
		print(j * 2)
	elif o <= A[-1]:
		print(j * 2 + 1)
	else:
		print(j * 2 + 2)


t = int(input())
for _ in range(t):
	(n, H) = map(int, input().split())
	weapon_damages = sorted(map(int, input().split()))
	used_weapon_1 = weapon_damages[-1]
	used_weapon_2 = weapon_damages[-2]
	used_weapon_damage = used_weapon_1 + used_weapon_2
	res = H // used_weapon_damage * 2
	if H % used_weapon_damage > 0:
		if H % used_weapon_damage <= used_weapon_1 or H % used_weapon_damage <= used_weapon_2:
			res += 1
		else:
			res += 2
	print(res)


for _ in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	xx = h // (a[-1] + a[-2])
	h -= xx * (a[-1] + a[-2])
	cnt = 2 * xx
	if h > 0:
		cnt += 1
		h -= a[-1]
	if h > 0:
		cnt += 1
		h -= a[-2]
	print(cnt)


t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	times = 0
	temp = a[0] + a[1]
	if h % temp == 0:
		print(h // temp * 2)
	elif h % temp == h:
		if h > a[0]:
			print(2)
		else:
			print(1)
	elif h % temp > 0:
		if h % temp <= a[0]:
			print(h // temp * 2 + 1)
		else:
			print(h // temp * 2 + 2)


tests = int(input())
for _ in range(0, tests):
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	both = arr[-1] + arr[-2]
	if h <= arr[-1]:
		print(1)
	else:
		if h % both == 0:
			ans1 = h // both * 2
		else:
			ans1 = (h // both + 1) * 2
		if (h + arr[-2]) % both == 0:
			ans2 = 2 * ((h + arr[-2]) // both) - 1
		else:
			ans2 = 2 * ((h + arr[-2]) // both + 1) - 1
		if ans1 > ans2:
			print(ans2)
		else:
			print(ans1)


for _ in range(int(input())):
	(n, h) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	a = l[0]
	b = l[1]
	c = a + b
	r = h % c
	if r == 0:
		print(2 * (h // c))
	elif r <= a:
		print(2 * (h // c) + 1)
	else:
		print(2 * (h // c) + 2)


from collections import Counter, deque
import math
from random import randint
from bisect import bisect
import sys
import re
MOD = 1000000007
MAX = sys.maxsize
MIN = -sys.maxsize

class get:

	def int():
		return list(map(int, input().split()))

	def str():
		return input().split()

	def float():
		return list(map(float, input().split()))

	def map():
		return map(int, input().split())

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

def solve():
	(n, H) = get.map()
	a = get.int()
	a.sort()
	r = H % (a[-1] + a[-2])
	res = H // (a[-1] + a[-2])
	res = 2 * res
	if r != 0:
		if r <= a[-1]:
			res += 1
		else:
			res += 2
	print(res)
for _ in range(int(input())):
	solve()


from math import ceil
for _ in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = ceil(h / (a[-1] + a[-2])) * 2
	if h - (ans // 2 * (a[-1] + a[-2]) - a[-2]) <= 0:
		ans -= 1
	print(ans)


for fgbhjm in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	x = a[-1]
	y = a[-2]
	ans = h // (x + y)
	if h <= x:
		print(1)
	elif h % (x + y) == 0:
		print(ans * 2)
	elif ans * (x + y) + x >= h:
		print(ans * 2 + 1)
	else:
		print(ans * 2 + 2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = sorted(list(map(int, input().split())), reverse=True)
	su = s[0] + s[1]
	print(m // su * 2 + (0 if m % su == 0 else 1 if m % su <= s[0] else 2))


def f():
	(n, h) = map(int, input().split())
	l = sorted(map(int, input().split()), reverse=True)
	(a, b) = (l[0], l[1])
	t = 1
	c = 2 * (h // (a + b))
	h %= a + b
	if h > a:
		c += 2
	elif h:
		c += 1
	return c
for _ in range(int(input())):
	print(f())


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	l.sort()
	a = l[len(l) - 1]
	b = l[len(l) - 2]
	c = a + b
	h = m // c
	d = m % c
	if h * c == m:
		print(h * 2)
	elif d <= a or d <= b:
		print(h * 2 + 1)
	else:
		print(h * 2 + 2)


def count_shots(aa, H):
	if len(aa) == 1:
		return (H + aa[0] - 1) // aa[0]
	else:
		aa.sort()
		v1 = aa[-1]
		v2 = aa[-2]
		count = H // (v1 + v2)
		H -= (v1 + v2) * count
		count *= 2
		while H > 0:
			v = v2 if count % 2 == 1 else v1
			H -= v
			count += 1
		return count
	return 0
n_t = int(input())
for t in range(n_t):
	(n, H) = map(int, input().split(' '))
	aa = list(map(int, input().split(' ')))
	assert len(aa) == n
	result = count_shots(aa, H)
	print(result)


def game(a, h):
	n = len(a)
	mx1 = 0
	mx2 = 0
	for i in range(n):
		if a[i] >= mx1:
			mx2 = mx1
			mx1 = a[i]
		elif a[i] < mx1 and a[i] >= mx2:
			mx2 = a[i]
	if h <= mx1:
		return 1
	if h <= mx1 + mx2:
		return 2
	temp = h % (mx1 + mx2)
	ans = h // (mx1 + mx2)
	ans = ans * 2
	if temp == 0:
		return ans
	if temp <= mx1:
		return ans + 1
	return ans + 2
t = int(input())
for i in range(t):
	(n, h) = input().split()
	n = int(n)
	h = int(h)
	a = [int(x) for x in input().split()]
	print(game(a, h))


for i in range(int(input())):
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	a = arr[-1]
	b = arr[-2]
	ans = h // (a + b) * 2
	h %= a + b
	if h == 0:
		print(ans)
	elif h - a <= 0:
		print(ans + 1)
	else:
		print(ans + 2)


t = int(input())
for i in range(t):
	(n, h) = map(int, input().split())
	n_ = list(map(int, input().split()))
	n_.sort(reverse=True)
	x = n_[0] + n_[1]
	y = int(h / x)
	z = h % x
	res = 2 * y
	if z == 0:
		pass
	elif z <= n_[0]:
		res += 1
	else:
		res += 2
	print(res)


t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	count = 0
	a.sort()
	if a[-1] >= h:
		print(1)
	elif a[-1] + a[-2] >= h:
		print(2)
	else:
		s = a[-1] + a[-2]
		f = h % s
		if f == 0:
			print(h // s * 2)
		elif f <= a[-1]:
			print(h // s * 2 + 1)
		else:
			print(h // s * 2 + 2)


import math
t = int(input())
for _ in range(t):
	(_, h) = [int(c) for c in input().split(' ')]
	a = [int(c) for c in input().split(' ')]
	m = max(a)
	if h <= m:
		print(1)
		continue
	k = 0
	a.remove(m)
	sm = max(a)
	k = math.floor(h / (m + sm))
	h = h % (m + sm)
	if h == 0:
		print(k * 2)
		continue
	if h <= m:
		print(k * 2 + 1)
		continue
	else:
		print(k * 2 + 2)


p = int(input())
while p:
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	d = a[n - 1] + a[n - 2]
	b = h // d
	c = h % d
	e = 0
	if c > a[n - 1] and c != 0:
		e += 2
	elif c != 0:
		e += 1
	e += 2 * b
	print(e)
	p -= 1


import math
t = int(input())
for i in range(t):
	(n, H) = map(int, input().split())
	A = list(map(int, input().split()))
	maxim1 = max(A)
	A[A.index(maxim1)] = 0
	maxim2 = max(A)
	maxim = maxim1 + maxim2
	if H // maxim == math.ceil(H / maxim):
		print(2 * (H // maxim))
	elif maxim * (H // maxim) + maxim1 >= H:
		print(2 * (H // maxim) + 1)
	else:
		print(2 * (H // maxim) + 2)


import math
import heapq
T = int(input())
for _ in range(T):
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	x = arr[-1] + arr[-2]
	z = h // x
	cnt = 0
	if h % x == 0:
		cnt = z * 2
	elif h % x <= arr[-1]:
		cnt = z * 2 + 1
	elif h % x > arr[-1]:
		cnt = z * 2 + 2
	print(cnt)


x = int(input())
for i in range(x):
	h = input().split(' ')
	w = input().split(' ')
	H = list(map(int, h))
	W = list(map(int, w))
	W.sort()
	if H[1] <= W[-1]:
		print(1)
	elif H[1] <= W[-1] + W[-2]:
		print(2)
	elif H[1] % (W[-1] + W[-2]) == 0:
		print(int(H[1] / (W[-1] + W[-2])) * 2)
	elif H[1] % (W[-1] + W[-2]) <= W[-1]:
		print(int(H[1] / (W[-1] + W[-2])) * 2 + 1)
	else:
		print(int(H[1] / (W[-1] + W[-2])) * 2 + 2)


t = int(input())
for _ in range(t):
	(n, H) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	l = a[-1]
	s = a[-2]
	if H <= l:
		print(1)
	elif H <= l + s:
		print(2)
	else:
		ans = 2 * (H // (l + s))
		h = ans // 2 * (l + s)
		while h < H:
			h += l
			ans += 1
			if h < H:
				h += s
				ans += 1
		print(ans)


t = int(input())
while t:
	t -= 1
	(n, h) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	(x, y) = (a[-1], a[-2])
	s = x + y
	u = h // s
	u = u * 2
	if h % s != 0:
		r = h % s
		if r <= x or r <= y:
			u += 1
		else:
			u += 2
	print(u)


for t in range(int(input())):
	(n, H) = [int(i) for i in input().split()]
	a = sorted([int(i) for i in input().split()])
	if a[-1] >= H:
		res = 1
	elif a[-1] + a[-2] >= H:
		res = 2
	else:
		b = H % (a[-1] + a[-2])
		if b == 0:
			res = H // (a[-1] + a[-2]) * 2
		elif b <= a[-1]:
			res = H // (a[-1] + a[-2]) * 2 + 1
		else:
			res = H // (a[-1] + a[-2]) * 2 + 2
	print(res)


total_tests = int(input())
from math import ceil
for i in range(total_tests):
	m = 0
	(n, H) = list(map(int, input().split(' ')))
	st = list(map(int, input().split(' ')))
	max1 = max(st)
	st.remove(max1)
	max2 = max(st)
	m = 2 * (H // (max1 + max2))
	if H % (max1 + max2) > max1:
		m += 2
	elif H % (max1 + max2) == 0:
		m += 0
	else:
		m += 1
	print(m)


t = int(input())
for i in range(t):
	(n, H) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	first = a[-1]
	second = a[-2]
	if first >= H:
		print(1)
	elif first + second >= H:
		print(2)
	else:
		rem = H // (first + second)
		mod = H % (first + second)
		if mod == 0:
			print(2 * rem)
		elif mod <= first:
			print(2 * rem + 1)
		else:
			print(2 * rem + 2)


for i in range(int(input())):
	(n, H) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	(i, count) = (0, 0)
	if H <= l[0]:
		print('1')
	else:
		q = H // (l[0] + l[1])
		if H % (l[0] + l[1]) == 0:
			print(2 * q)
		elif H % (l[0] + l[1]) <= l[0]:
			print(2 * q + 1)
		else:
			print(2 * q + 2)


def solve():
	(n, h) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort()
	x = a[n - 1]
	y = 0
	if n >= 2:
		y = a[n - 2]
	k = int(h / (x + y))
	h = h - k * (x + y)
	cnt = k * 2
	if h > 0:
		cnt = cnt + 1
		h -= x
	if h > 0:
		cnt = cnt + 1
		h -= y
	print(cnt)
test = int(input())
while test > 0:
	test = test - 1
	solve()


t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	(x, y, *z) = sorted(map(int, input().split()), reverse=True)
	s = x + y
	(d, r) = (h // s, h % s)
	ans = d * 2
	if r > x:
		ans += 2
	elif r > 0:
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	m1 = arr[-1]
	m2 = arr[-2]
	if m1 >= h:
		print(1)
	else:
		p = m1 + m2
		(q, rem) = (h // p, h % p)
		if rem > 0:
			if rem <= m1:
				print(2 * q + 1)
			else:
				print(2 * q + 2)
		else:
			print(2 * q)


def mini(list1):
	mx = max(list1[0], list1[1])
	secondmax = min(list1[0], list1[1])
	n = len(list1)
	for i in range(2, n):
		if list1[i] > mx:
			secondmax = mx
			mx = list1[i]
		elif list1[i] > secondmax:
			secondmax = list1[i]
	return (mx, secondmax)
t = int(input())
c = 0
for i in range(t):
	(n, h) = map(int, input().split())
	dmg = list(map(int, input().split()))
	(mx, secondmx) = mini(dmg)
	if h <= mx:
		print(1)
	elif h % (mx + secondmx) == 0:
		print(2 * (h // (mx + secondmx)))
	else:
		q = 2 * (h // (mx + secondmx))
		r = h - q / 2 * (mx + secondmx)
		if r <= mx:
			print(q + 1)
		else:
			print(q + 2)


T = int(input())
while T:
	(n, H) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	at = arr[0] + arr[1]
	if H % at:
		if arr[0] < H % at:
			print(H // at * 2 + 2)
		else:
			print(H // at * 2 + 1)
	else:
		print(H // at * 2)
	T -= 1


def fun(ls, lt):
	(n, h) = lt
	ls = sorted(ls)
	mx = ls[-1]
	mn = ls[-2]
	sm = mx + mn
	times = h // sm * 2
	h = h % sm
	count = 0
	while h > 0:
		if count % 2 == 0:
			h -= mx
			times += 1
		else:
			h -= mn
			times += 1
		count += 1
	print(times)
T = int(input())
for i in range(T):
	lt = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	fun(ls, lt)


def parse_n_solve():
	t = int(input())
	for i in range(t):
		(n, h) = list(map(int, input().split()))
		ais = list(map(int, input().split()))
		ais = sorted(ais, reverse=True)
		if ais[0] >= h:
			print(1)
		elif ais[0] + ais[1] >= h:
			print(2)
		else:
			mod = h % (ais[0] + ais[1])
			div = int(h / (ais[0] + ais[1]))
			if mod == 0:
				print(div * 2)
			elif mod > ais[0]:
				print(div * 2 + 2)
			else:
				print(div * 2 + 1)
parse_n_solve()


def gamer_hemose(H, a):
	best_damage = a[0] + a[1]
	s = H // best_damage * 2
	H %= best_damage
	if H > 0:
		s += 1
		H -= a[0]
	if H > 0:
		s += 1
	return s
t = int(input())
for _ in range(t):
	(n, H) = map(int, input().split(' '))
	a = sorted(map(int, input().split(' ')), reverse=True)
	print(gamer_hemose(H, a))


def solve(n, H, hps):
	hps = sorted(hps)
	(one, two) = (hps[-1], hps[-2])
	count = 0
	total = one + two
	if H > total:
		count += 2 * (H // total)
		H %= total
	if H > 0:
		H -= one
		count += 1
	if H > 0:
		H -= two
		count += 1
	return count

def main():
	testcases = int(input())
	for _ in range(testcases):
		(n, H) = [int(x) for x in input().split()]
		hps = [int(x) for x in input().split()]
		ans = solve(n, H, hps)
		print(ans)
main()


for _ in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	an = 2 * (h // (a[-1] + a[-2]))
	if h % (a[-1] + a[-2]) == 0:
		print(an)
	elif h % (a[-1] + a[-2]) - a[-1] > 0:
		print(an + 2)
	else:
		print(an + 1)


def second_largest(numbers):
	m1 = m2 = float('-inf')
	for x in numbers:
		if x > m2:
			if x >= m1:
				(m1, m2) = (x, m1)
			else:
				m2 = x
	return [m1, m2]
for _ in range(int(input())):
	(n, h) = map(int, input().split())
	(*wep,) = map(int, input().split())
	wep = second_largest(wep)
	sm = wep[0] + wep[1]
	if h // sm:
		aa = h // sm
		s = aa * sm
		h -= s
		aa *= 2
		if h == 0:
			pass
		elif h > wep[0]:
			aa += 2
		else:
			aa += 1
		print(aa)
	elif h > wep[0]:
		print(2)
	else:
		print(1)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = list(map(int, input().split()))
	li = [int(x) for x in input().split()]
	li.sort()
	count = 0
	add = li[a - 1] + li[a - 2]
	count += b // add
	ans = 2 * count
	left = b - add * count
	if left == 0:
		print(ans)
	else:
		if left > li[a - 1]:
			left -= li[a - 1]
			ans += 2
		else:
			ans += 1
		print(ans)


for i in range(int(input())):
	(n, h) = map(int, input().split())
	l = list(map(int, input().split()))
	l = sorted(l)
	count = 2 * (h // (l[n - 1] + l[n - 2]))
	a = h % (l[n - 1] + l[n - 2])
	if a == 0:
		count += 0
	elif a > l[n - 1]:
		count += 2
	else:
		count += 1
	print(count)


p = lambda : map(int, input().split())
(T,) = p()
for _ in range(T):
	(n, h) = p()
	(x, y) = sorted(p())[-2:]
	k = h // (x + y)
	h -= k * (x + y)
	print(2 * k + (2 if h > y else 1 if h else 0))


t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	m = l[0] + l[1]
	x = 2 * (h // m)
	h %= m
	if h > l[0]:
		x += 2
	elif h > 0:
		x += 1
	print(x)


def solve():
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	max1 = arr[n - 1]
	max2 = arr[n - 2]
	tot = max1 + max2
	ans = h // tot * 2
	h = h % tot
	if h > 0:
		h -= max1
		ans += 1
	if h > 0:
		h -= max2
		ans += 1
	print(ans)
t = int(input())
for i in range(t):
	solve()


for t in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	w1 = a[0]
	w2 = a[1]
	i = 0
	count = 0
	ans = 2 * (h // (w1 + w2))
	rem = h % (w1 + w2)
	if rem > 0:
		if w1 >= rem:
			ans += 1
		else:
			ans += 2
	print(ans)


t = int(input())
for i in range(t):
	(n, h) = map(int, input().split())
	a = [x for x in map(int, input().split())]
	a.sort()
	x = a[n - 1] + a[n - 2]
	c = 2 * (h // x)
	h = h % x
	if h > a[n - 1]:
		c += 2
	elif h > 0:
		c += 1
	print(c)


for step in range(int(input())):
	(n, H) = map(int, input().split())
	weapons = list(map(int, input().split()))
	weapons.sort()
	strongest = weapons[-1]
	secstrong = weapons[-2]
	ans = 0
	mog = H // (strongest + secstrong)
	ans += 2 * mog
	leftover = H % (strongest + secstrong)
	if 0 < leftover <= strongest:
		ans += 1
	elif leftover == 0:
		pass
	else:
		ans += 2
	print(ans)


for i in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	if h % (a[0] + a[1]) == 0:
		print(h // (a[0] + a[1]) * 2)
	elif h % (a[0] + a[1]) <= a[0]:
		print(h // (a[0] + a[1]) * 2 + 1)
	else:
		print(h // (a[0] + a[1]) * 2 + 2)


Input = '\n3\n2 4\n3 7\n2 6\n4 2\n3 11\n2 1 7\n'[1:-1].split('\n')
t = int(input())
for i in range(t):
	(n, H) = map(int, input().split())
	a = sorted(map(int, input().split()), reverse=True)
	(A, B) = a[:2]
	(Count, H) = divmod(H, A + B)
	if H <= 0:
		print(Count * 2)
	elif H > A:
		print(Count * 2 + 2)
	else:
		print(Count * 2 + 1)


t = int(input())
for _ in range(t):
	(n, H) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	ans = H // (a[0] + a[1])
	H -= (a[0] + a[1]) * ans
	ans *= 2
	while H > 0:
		H -= a[ans % 2]
		ans += 1
	print(ans)


T = int(input())
for t in range(T):
	(n, H) = [int(k) for k in input().split(' ')]
	a = [int(k) for k in input().split(' ')]
	(M, m) = (0, 0)
	for k in a:
		if k >= M:
			m = M
			M = k
		elif k > m:
			m = k
	a = [M, m]
	ans = H // (M + m) * 2
	rem = H % (M + m)
	if rem == 0:
		print(ans)
	elif rem <= M:
		print(ans + 1)
	else:
		print(ans + 2)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = sorted(map(int, input().split()), reverse=True)
	(x, y) = (l[0], l[1])
	flag = 0
	c = 0
	ans = b // (x + y) * 2
	test = b % (x + y)
	if test > x:
		ans += 2
	elif test > 0:
		ans += 1
	print(ans)


for i in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	h = h - a[-1]
	count = 1
	if h > 0:
		h = h - a[-2]
		count += 1
		if h > 0:
			t = a[-1] + a[-2]
			count = count + 2 * (h // t)
			h = h % t
			if h > 0:
				h = h - a[-1]
				count += 1
				if h > 0:
					count += 1
	print(count)


import math
t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	l = [int(i) for i in input().split()]
	l.sort()
	s = l[-1] + l[-2]
	if l[-1] >= h:
		print('1')
	elif h % s == 0:
		print(h // s * 2)
	elif h % s <= l[-1]:
		print(h // s * 2 + 1)
	else:
		print(h // s * 2 + 2)


t = int(input())
for _ in range(t):
	(n, h) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	(a, b) = (arr[0], arr[1])
	count = 0
	total = a + b
	count += 2 * (h // total)
	rem = h % total
	if rem == 0:
		count += 0
	elif rem <= a:
		count += 1
	else:
		count += 2
	print(count)


t = int(input())
for _ in range(t):
	(n, H) = list(map(int, input().split()))
	damage = list(map(int, input().split()))
	damage.sort(reverse=True)
	d1 = damage[0]
	d2 = damage[1]
	if H <= d1:
		print(1)
	else:
		q = H // (d1 + d2)
		r = H % (d1 + d2)
		if r == 0:
			print(2 * q)
		elif r <= d1:
			print(2 * q + 1)
		else:
			print(2 * q + 2)


def main():
	t = int(input())
	for i in range(t):
		(n, H) = map(int, input().split())
		a = list(map(int, input().split()))
		a1 = max(a)
		del a[a.index(a1)]
		a2 = max(a)
		a = [a1, a2]
		co = 2 * (H // (a1 + a2))
		k = 2
		if H % (a1 + a2) != 0:
			co += 1
			if H % (a1 + a2) > a1:
				co += 1
		print(co)
main()


t = int(input())
for a in range(t):
	weapons_health = [int(i) for i in input().split()]
	damage = [int(j) for j in input().split()]
	damage = sorted(damage)
	H = weapons_health[1]
	gun_a = damage[-1]
	gun_b = damage[-2]
	dam = gun_a + gun_b
	if H % dam == 0:
		cnt = H // dam
	else:
		cnt = int(H / dam + 1)
	if dam * cnt - gun_b >= H:
		print(2 * cnt - 1)
	else:
		print(2 * cnt)


T = int(input())
while T > 0:
	(n, H) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	max1 = max(A)
	A.remove(max1)
	max2 = max(A)
	if H <= max1:
		print(1)
	elif H <= max1 + max2:
		print(2)
	else:
		val = int(H / (max1 + max2))
		count = val * 2
		if H - val * (max1 + max2) <= 0:
			print(count)
		else:
			rem = H - val * (max1 + max2)
			if rem <= max1:
				print(count + 1)
			else:
				print(count + 2)
	T = T - 1


R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, h) = R()
	(*_, x, y) = sorted(R())
	s = x + y
	print(h // s * 2 + (h % s > 0) + (h % s > y))


for _ in range(int(input())):
	(n, h) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort(reverse=True)
	ans = 2 * (h // (a[0] + a[1]))
	h -= ans // 2 * (a[0] + a[1])
	if h > 0:
		ans += 1
		h -= a[0]
	if h > 0:
		ans += 1
		h -= a[1]
	print(ans)


for i in range(int(input())):
	health = int(input().split()[1])
	all_damages = input().split()
	all_damages = [int(x) for x in all_damages]
	if len(all_damages) == 1:
		print(1)
		continue
	max_damage = max(all_damages)
	all_damages.remove(max_damage)
	max2 = max(all_damages)
	counter = 0
	two_damages = max_damage + max2
	if two_damages < health:
		counter = health // two_damages * 2
		left = health % two_damages
		if left > 0:
			counter += 1
		if left > max_damage:
			counter += 1
	elif max_damage >= health:
		counter = 1
	else:
		counter = 2
	print(counter)


t = int(input())
for i in range(t):
	(n, H) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	(a, b) = (arr[-1], arr[-2])
	ans = H // (a + b)
	H -= ans * (a + b)
	ans *= 2
	if H > a:
		ans += 2
	elif H != 0:
		ans += 1
	print(ans)


def main():

	def solve(n, h, a):
		b = c = -1
		for x in a:
			if x > b:
				c = b
				b = x
			elif x > c:
				c = x
		(q, r) = divmod(h, b + c)
		if r > b:
			return 2 * q + 2
		elif r > 0:
			return 2 * q + 1
		return 2 * q
	t = int(input())
	ans = []
	for _ in range(t):
		(n, h) = [int(x) for x in input().split()]
		a = [int(x) for x in input().split()]
		ans.append(solve(n, h, a))
	print('\n'.join(map(str, ans)))
import sys, threading
input = sys.stdin.readline
thread = threading.Thread(target=main)
thread.start()
thread.join()


from random import *
from math import *
T = int(input())
for t in range(T):
	(n, H) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	ans = 0
	(a, b) = (A[-1], A[-2])
	ans += H // (a + b) * 2
	H %= a + b
	while H > 0:
		if ans % 2 == 0:
			H -= a
		else:
			H -= b
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a1ma = a[-1]
	a2ma = a[-2]
	tma = a1ma + a2ma
	ans = h // tma
	mo = h % tma
	if mo == 0:
		print(ans * 2)
	elif mo <= a1ma:
		print(ans * 2 + 1)
	else:
		print(ans * 2 + 2)