#P1692E. Binary Deque
Binary Deque
Description
Slavic has an array of length consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array.
What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to after performing all the operations? In case the sum can't be obtained after any amount of operations, you should output -1.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers and () — the length of the array and the needed sum of elements.
The second line of each test case contains integers () — the elements of the array.
It is guaranteed that the sum of over all test cases doesn't exceed .
For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to , or -1 if obtaining an array with sum isn't possible.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers and () — the length of the array and the needed sum of elements.
The second line of each test case contains integers () — the elements of the array.
It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to , or -1 if obtaining an array with sum isn't possible.
Note
In the first test case, the sum of the whole array is from the beginning, so we don't have to make any operations.
In the second test case, the sum of the array is and we want it to be equal to , so we should remove the first element. The array turns into , which has a sum equal to .
In the third test case, the sum of the array is and we need it to be . We can obtain such a sum by removing the first two elements and the last element, doing a total of three operations. The array turns into , which has a sum equal to .