
Given:
‘N’ = 6, ‘C’ = 23
‘A’[] = {5, 19, 13, 2, 4, 0}
‘B’[] = {10, 4, 7, 4, 5, 14}
The max-length subarray will be 2, consider the subarray from 3 to 4 (0-based indexing) and here, the subarray sum of ‘A’ = 6 max element in ‘B’ = 5. Therefore 6*2 + 5 = 17, Which is less than 23. Hence 2 is the final answer.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains two space-separated integers, ‘N,’ where ‘N’ is the number of elements of the array and ‘C’ where ‘C’ is the given integer.
The second line of each test case contains ‘N’ space-separated integers, denoting the array elements.
For each test case, You are supposed to return an integer that denotes the maximum length subarray.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 5000
0 <= 'ARR[i]’ <= 10 ^ 6
Time Limit: 1sec.
The idea is to brute force to find the maximum length subarray which satisfies the given condition.
The idea is to optimize the above approach using binary search, since for some length ‘K’, if ‘K’ is possible, then obviously ‘K - 1’ will also be possible. Therefore we binary search over the length of the array.
The steps are as follows: