#C11596. Smallest Subarray with Sum Greater than X

    ID: 40929 Type: Default 1000ms 256MiB

Smallest Subarray with Sum Greater than X

Smallest Subarray with Sum Greater than X

You are given an array of integers and a target value x. Your task is to determine the length of the smallest contiguous subarray such that the sum of the elements in this subarray is strictly greater than x. If no such subarray exists, output -1.

Note: The subarray must consist of consecutive elements. The answer should be the minimum number of consecutive elements required whose sum is greater than x.

Formally, given an array a1, a2, ..., an and an integer x, find the minimum length l such that there exists an index i with \[ a_i + a_{i+1} + \cdots + a_{i+l-1} > x \] If no such l exists, output -1.

inputFormat

The first line of input contains two integers n and x separated by a space, where n is the number of elements in the array and x is the target sum.

The second line contains n space-separated integers which represent the array.

outputFormat

Output a single integer representing the length of the smallest contiguous subarray whose sum is greater than x. If no such subarray exists, output -1.

## sample
6 51
1 4 45 6 0 19
3

</p>