You have N stacks of books. Each stack of books has some non zero height Hi equal to the number of books on that stack ( considering all the books are identical and each book has a height of 1 unit ). In one move, you can select any number of consecutive stacks of books such that the height of each selected stack of books Hi <= K . Once such a sequence of stacks is chosen , You can collect any number of books from the chosen sequence of stacks .
What is the maximum number of books that you can collect this way ?
Input:
The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. First line of each test case contains two space separated integers N and K where N is the number of stacks of books. Second line of each test case contains N space separated integers denoting the number of books Hi on each stack.
Output:
For each test case, print the maximum number of books you can collect.
Constraints:
1<=T<=105
1<=N<=105
1<=K<=109
1<=Hi<=109
Example(To be used only for expected output):
Input
2
8 1
3 2 2 3 1 1 1 3
8 2
3 2 2 3 1 1 1 3
 
Output
3
4
Explanation :
For the first test case
N = 8 , K = 1 { 3 2 2 3 1 1 1 3 }
We can collect maximum books from consecutive stacks numbered 5, 6 and 7 having height less than equal to K.
For the second test case
N = 8 , K = 2 { 3 2 2 3 1 1 1 3 }
We can collect maximum books from consecutive stacks numbered 2 and 3 having height less than equal to K.

Source: geeksforgeeks | Difficulty: EASY
Tags: Dynamic programming

Data structures

Starter code: 
class Solution:
    #Your task is to complete this function
    #Function should return an integer
    #a - list/array containing height of stack's respectively
    def max_Books(self, n, k, a):
        #code here

Solutions:
class Solution:

	def max_Books(self, n, k, a):
		sm = 0
		sl = 0
		for i in range(n):
			if a[i] > k:
				sl = 0
			else:
				sl += a[i]
				sm = max(sl, sm)
		return sm


class Solution:

	def max_Books(self, n, k, a):
		for i in range(n):
			if a[i] > k:
				a[i] = 0
		for i in range(1, n):
			if a[i] == 0:
				continue
			else:
				a[i] += a[i - 1]
		return max(a)


class Solution:

	def max_Books(self, n, k, a):
		maxx = 0
		curr_maxx = 0
		for i in range(n):
			if a[i] <= k:
				curr_maxx += a[i]
			else:
				curr_maxx = 0
			if curr_maxx > maxx:
				maxx = curr_maxx
		return maxx


class Solution:

	def max_Books(self, n, k, a):
		max_book = 0
		current_max = 0
		for i in a:
			if i <= k:
				current_max += i
				max_book = max(max_book, current_max)
			else:
				current_max = 0
		return max_book


class Solution:

	def max_Books(self, n, k, a):
		g = 0
		maxh = 0
		for i in range(n):
			if arr[i] <= k:
				g = g + arr[i]
				maxh = max(maxh, g)
			else:
				maxh = max(maxh, g)
				g = 0
		return maxh


class Solution:

	def max_Books(self, n, k, a):
		max_sum_so_far = 0
		max_sum_end = 0
		for i in range(n):
			if a[i] <= k:
				max_sum_so_far += a[i]
				if max_sum_so_far > max_sum_end:
					max_sum_end = max_sum_so_far
			else:
				max_sum_so_far = 0
		return max_sum_end


class Solution:

	def max_Books(self, n, k, a):
		total = 0
		max_ = 0
		for i in range(n):
			if a[i] <= k:
				total += a[i]
				max_ = max(max_, total)
			else:
				max_ = max(max_, total)
				total = 0
		return max_


class Solution:

	def max_Books(self, n, k, a):
		maxi = 0
		summa = 0
		for item in a:
			if item <= k:
				summa += item
			else:
				maxi = max(maxi, summa)
				summa = 0
		return max(maxi, summa)


class Solution:

	def max_Books(self, n, k, a):
		sum1 = 0
		ma = 0
		for i in range(n):
			ci = a[i]
			if ci <= k:
				sum1 += ci
				ma = max(ma, sum1)
			else:
				ma = max(ma, sum1)
				sum1 = 0
		return ma


class Solution:

	def max_Books(self, n, k, a):
		maxs = [0] * len(a)
		if a[0] <= k:
			maxs[0] = a[0]
		for i in range(1, len(a)):
			if a[i] <= k:
				maxs[i] = maxs[i - 1] + a[i]
		return max(maxs)


class Solution:

	def max_Books(self, n, k, a):
		dp = [0] * n
		dp[0] = a[0] if a[0] <= k else 0
		for i in range(1, n):
			dp[i] = dp[i - 1] + a[i] if a[i] <= k else 0
		return max(dp)
		Max_ans = 0
		current_ans = 0
		for i in range(len(a)):
			if a[i] <= k:
				current_ans += a[i]
				Max_ans = max(Max_ans, current_ans)
			else:
				current_ans = 0
		return Max_ans


class Solution:

	def max_Books(self, n, k, a):
		c = 0
		ans = 0
		for i in range(n):
			if a[i] <= k:
				c += a[i]
				ans = max(ans, c)
			else:
				c = 0
		return ans


class Solution:

	def max_Books(self, n, k, a):
		count = 0
		books = 0
		for i in range(0, len(a)):
			if a[i] <= k:
				books = books + a[i]
			elif a[i] > k:
				books = 0
			count = max(count, books)
		return count


class Solution:

	def max_Books(self, n, k, a):
		s = 0
		ms = 0
		for i in range(n):
			if a[i] <= k:
				s += a[i]
			else:
				ms = max(ms, s)
				s = 0
		ms = max(ms, s)
		return ms


class Solution:

	def max_Books(self, n, k, a):
		b = []
		books = 0
		if a[0] <= k:
			books = a[0]
			b.append(a[0])
		for i in range(1, n):
			if a[i] <= k:
				if a[i - 1] <= k:
					books += a[i]
				else:
					books = a[i]
			else:
				books = 0
			b.append(books)
		return max(b)


class Solution:

	def max_Books(self, n, k, arr):
		book = 0
		stack = 0
		for i in range(n):
			if arr[i] <= k:
				stack += arr[i]
				book = max(stack, book)
			else:
				stack = 0
		return book


class Solution:

	def max_Books(self, n, k, a):
		maxi = 0
		count = 0
		for i in range(n):
			if a[i] <= k:
				count += a[i]
				maxi = max(maxi, count)
			else:
				count = 0
		return maxi


class Solution:

	def max_Books(self, n, k, a):
		mx = 0
		cur_max = 0
		for i in range(n):
			if a[i] <= k:
				cur_max += a[i]
			else:
				mx = max(cur_max, mx)
				cur_max = 0
		mx = max(cur_max, mx)
		return mx


class Solution:

	def max_Books(self, n, k, a):
		maxn = 0
		summ = 0
		for x in range(n):
			if a[x] <= k:
				summ += a[x]
				maxn = max(maxn, summ)
			else:
				maxn = max(maxn, summ)
				summ = 0
		return maxn


class Solution:

	def max_Books(self, n, k, a):
		cur = 0
		maxsum = 0
		for i in range(n):
			if a[i] <= k:
				cur += a[i]
				maxsum = max(cur, maxsum)
			else:
				maxsum = max(cur, maxsum)
				cur = 0
		return maxsum


class Solution:

	def max_Books(self, n, k, a):
		ma = 0
		su = 0
		i = 0
		while i < n:
			while a[i] <= k:
				su += a[i]
				i += 1
				if i > n - 1:
					break
			ma = max(ma, su)
			su = 0
			i += 1
		return ma


class Solution:

	def max_Books(self, n, k, a):
		max_val = 0
		temp = 0
		i = 0
		while i < n:
			if a[i] <= k:
				temp += a[i]
			else:
				max_val = max(max_val, temp)
				temp = 0
			i += 1
		return max(max_val, temp)


class Solution:

	def max_Books(self, n, k, a):
		max_books = -1
		total = 0
		for i in range(n):
			if arr[i] <= k:
				total += arr[i]
			else:
				max_books = max(max_books, total)
				total = 0
		return max(max_books, total)


class Solution:

	def max_Books(self, n, k, a):
		dp = [0 for x in range(n + 1)]
		for i in range(n):
			if a[i] <= k:
				dp[i] = max(dp[i - 1] + a[i], dp[i])
		return max(dp)


class Solution:

	def max_Books(self, n, k, a):
		maxCount = 0
		countTillNow = 0
		i = 0
		while i < n:
			if a[i] <= k:
				countTillNow += a[i]
			maxCount = max(maxCount, countTillNow)
			if a[i] > k:
				countTillNow = 0
			i += 1
		return maxCount
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		temp = list(map(int, input().strip().split()))
		n = temp[0]
		k = temp[1]
		arr = list(map(int, input().strip().split()))
		ob = Solution()
		print(ob.max_Books(n, k, arr))


class Solution:

	def max_Books(self, n, k, a):
		c = 0
		m = 0
		for i in a:
			if i <= k:
				c = c + i
			else:
				c = 0
			m = max(m, c)
		return m
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		temp = list(map(int, input().strip().split()))
		n = temp[0]
		k = temp[1]
		arr = list(map(int, input().strip().split()))
		ob = Solution()
		print(ob.max_Books(n, k, arr))


class Solution:

	def max_Books(self, n, k, a):
		i = 0
		maxc = -1
		while i <= n - 1:
			count = 0
			while i <= n - 1 and a[i] <= k:
				count += a[i]
				i += 1
			if count > maxc:
				maxc = count
				i -= 1
			i += 1
		return maxc


class Solution:

	def max_Books(self, n, k, a):
		i = 0
		li = []
		while i < n:
			ans = 0
			if a[i] <= k:
				ans += a[i]
				j = i + 1
				while j < n and a[j] <= k:
					ans += a[j]
					j = j + 1
				li.append(ans)
			i = i + 1
		return max(li)


class Solution:

	def max_Books(self, n, k, a):
		maxAns = 0
		ans = 0
		for num in a:
			if num <= k:
				ans += num
			else:
				maxAns = max(ans, maxAns)
				ans = 0
		return max(maxAns, ans)


class Solution:

	def max_Books(self, n, k, a):
		i = 0
		maxans = 0
		while i < n:
			if a[i] <= k:
				max1 = 0
				while i < n and a[i] <= k:
					max1 += a[i]
					maxans = max(maxans, max1)
					i += 1
			i += 1
		return maxans


class Solution:

	def max_Books(self, n, k, a):
		if a[0] <= k:
			s = a[0]
			ma = s
		else:
			s = 0
			ma = 0
		for i in range(1, n):
			if a[i] <= k and a[i - 1] > k:
				if s > ma:
					ma = s
				s = a[i]
			elif a[i] <= k and a[i - 1] <= k:
				s += a[i]
		if s > ma:
			ma = s
		return ma


class Solution:

	def max_Books(self, n, k, a):
		dp = [0 for _ in range(len(a))]
		if arr[0] <= k:
			dp[0] = arr[0]
		for i in range(1, len(a)):
			if arr[i] <= k:
				dp[i] = dp[i - 1] + a[i]
		return max(dp)


class Solution:

	def max_Books(self, n, k, a):
		best = 0
		count = 0
		for stack in a:
			if stack <= k:
				count += stack
				best = max(best, count)
			else:
				count = 0
		best = max(best, count)
		return best


class Solution:

	def max_Books(self, n, k, a):
		s = 0
		ans = 0
		for ele in a:
			if ele <= k:
				s += ele
			else:
				ans = max(ans, s)
				s = 0
		return max(ans, s)


class Solution:

	def max_Books(self, n, k, a):
		s = 0
		msum = 0
		for i in range(n):
			if a[i] <= k:
				s = s + a[i]
			elif a[i] > k:
				if s > msum:
					msum = s
				s = 0
		if s > msum:
			msum = s
		return msum


class Solution:

	def max_Books(self, n, k, a):
		a.append(100000000000000)
		s = 0
		max = 0
		for i in range(n + 1):
			if a[i] <= k:
				s += a[i]
			else:
				if s > max:
					max = s
				s = 0
		return max


class Solution:

	def max_Books(self, n, k, a):
		sum = 0
		max_sum = 0
		for i in range(n):
			if a[i] <= k:
				sum += a[i]
				max_sum = max(max_sum, sum)
			elif a[i] > k:
				sum = 0
		return max_sum


class Solution:

	def max_Books(self, n, k, a):
		m = 0
		i = 0
		s = 0
		while i < n:
			if a[i] <= k:
				s += a[i]
			else:
				if s > m:
					m = s
				s = 0
			i += 1
		if s > m:
			m = s
		return m


class Solution:

	def max_Books(self, n, k, a):
		count = 0
		l = []
		val = 0
		for i in range(n):
			if a[i] <= k:
				count += 1
				val = val + a[i]
				l.append(val)
			else:
				count = 0
				val = 0
		return max(l)


class Solution:

	def max_Books(self, n, k, a):
		max_book_count = -1
		i = 0
		while i < n:
			book_count = 0
			while i < n and a[i] <= k:
				book_count += a[i]
				i += 1
			max_book_count = max(max_book_count, book_count)
			i += 1
		return max_book_count


class Solution:

	def max_Books(self, n, k, a):
		i = 0
		j = 0
		maxans = -float('inf')
		ans = 0
		while j < n:
			if k < a[j]:
				if ans > maxans:
					maxans = ans
				ans = 0
			else:
				ans += a[j]
			if j == n - 1:
				if ans > maxans:
					maxans = ans
			j += 1
		return maxans


class Solution:

	def max_Books(self, n, k, a):
		cur_val = 0
		max_val = 0
		for i in range(n):
			if a[i] <= k:
				cur_val += a[i]
			max_val = max(max_val, cur_val)
			if a[i] > k:
				cur_val = 0
		return max_val


class Solution:

	def max_Books(self, n, k, a):
		ans = curr = 0
		for (i, num) in enumerate(a):
			if num <= k:
				curr += num
				ans = max(ans, curr)
			else:
				curr = 0
		return ans


class Solution:

	def max_Books(self, n, k, a):
		meh = msf = 0
		for i in range(n):
			if a[i] <= k:
				meh += a[i]
			msf = max(msf, meh)
			if a[i] > k:
				meh = 0
		return msf


class Solution:

	def max_Books(self, n, k, a):
		dp = [0 for _ in range(n)]
		for i in range(n):
			for j in range(i, n):
				if a[j] <= k:
					dp[i] += a[j]
				else:
					break
		return max(dp)


class Solution:

	def max_Books(self, n, k, arr):
		ans = 0
		maxi = 0
		for i in range(n):
			if arr[i] <= k:
				maxi += arr[i]
				ans = max(ans, maxi)
			else:
				maxi = 0
		return ans