#C9397. Smallest Subarray Length

    ID: 53485 Type: Default 1000ms 256MiB

Smallest Subarray Length

Smallest Subarray Length

You are given an array of integers and a target sum \(S\). Your task is to determine the smallest length of a contiguous subarray whose sum is at least \(S\). If no such subarray exists, output 0.

This problem can be efficiently solved using the sliding window technique. For instance, if the array is [1, 2, 3, 4, 5, 6, 7, 8] and \(S = 15\), the subarray [7, 8] is the smallest contiguous segment whose sum is \(15\) or more, and its length is 2.

inputFormat

The input is read from standard input.

The first line contains two integers \(n\) and \(S\), where \(n\) is the number of elements in the array and \(S\) is the target sum.

The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output a single integer to standard output, which represents the length of the smallest contiguous subarray with a sum at least \(S\). If no such subarray exists, output 0.

## sample
8 15
1 2 3 4 5 6 7 8
2