[Solution] Binary Deque Codeforces Solution | Codeforces Problem Solution 2022
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.
No comments:
Post a Comment