#K40297. Minimum Length Subarray Sum

    ID: 26611 Type: Default 1000ms 256MiB

Minimum Length Subarray Sum

Minimum Length Subarray Sum

Given an array of positive integers and a target integer \(x\), determine the minimum length of a contiguous subarray such that the sum of its elements is greater than or equal to \(x\). If no such subarray exists, output \(-1\).

This problem can be efficiently solved using a sliding window technique.

inputFormat

The input is provided via standard input (stdin). The first line contains two integers \(n\) and \(x\), where \(n\) represents the number of elements in the array, and \(x\) is the target sum. The second line contains \(n\) space-separated positive integers representing the array elements.

Example:

8 7
2 3 1 2 4 3 2 1

outputFormat

Output a single integer to standard output (stdout), which is the minimum length of the contiguous subarray whose sum is at least \(x\). If no such subarray exists, output \(-1\).

## sample
8 7
2 3 1 2 4 3 2 1
2