#K46257. Minimum Subarray Length Sum Problem
Minimum Subarray Length Sum Problem
Minimum Subarray Length Sum Problem
You are given an array of n integers and a target sum \( x \). Your task is to find the length of the smallest contiguous subarray whose sum is greater than or equal to \( x \). If no such subarray exists, output -1.
Note: A subarray is a continuous portion of the array. The answer is the minimum length of such a subarray.
Example:
Input: 6 7 2 1 5 2 3 2</p>Output: 2
In the above example, the subarray [5,2] has a sum equal to 7 and its length is 2, which is the smallest possible.
inputFormat
The first line of the input contains a single integer \( T \) — the number of test cases. Each test case follows:
- The first line of each test case contains two integers \( n \) and \( x \), where \( n \) is the number of elements in the array and \( x \) is the target sum.
- The second line contains \( n \) space-separated integers representing the array.
All input is provided via standard input (stdin).
outputFormat
For each test case, output a single integer — the length of the smallest contiguous subarray whose sum is at least \( x \), or -1 if no such subarray exists. Each result should be printed on a new line using standard output (stdout).
## sample5
6 7
2 1 5 2 3 2
5 11
1 2 3 4 5
3 100
1 1 1
5 15
1 2 3 4 5
6 5
5 1 1 1 1 1
2
3
-1
5
1
</p>