GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 14 June 2022

[Solution] Binary Deque Codeforces Solution | Codeforces Problem Solution 2022

E. Binary Deque
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Slavic has an array of length n 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 s after performing all the operations? In case the sum s can't be obtained after any amount of

Solution Click Below:-  CLICK HERE

 operations, you should output -1.

Input

The first line contains a single integer t (1t104) — the number of test cases.

The first line of each test case contains two integers n and s (1n,s2105) — the length of the array and the needed sum of elements.

The second line of each test case contains n integers ai (0ai1) — the elements of the array.

It is guaranteed that the sum of n over all test cases doesn't exceed 2105.

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 s, or -1 if obtaining an array with sum s isn't possible.

No comments:

Post a Comment