#C5477. Longest Contiguous Subarray with Given Sum

    ID: 49130 Type: Default 1000ms 256MiB

Longest Contiguous Subarray with Given Sum

Longest Contiguous Subarray with Given Sum

You are given an array of integers and a target value \(T\). Your task is to find the length of the longest contiguous subarray whose sum equals \(T\). If no such subarray exists, print 0.

For example, consider the array [1, -1, 5, -2, 3] with target \(T=3\). The longest subarray that sums to 3 is [1, -1, 5, -2] which has length 4.

Input Format: The first line of input contains two integers: \(n\) (the number of elements in the array) and \(T\) (the target sum). The second line contains \(n\) space-separated integers.

Output Format: Print a single integer representing the length of the longest contiguous subarray that sums to \(T\). If no such subarray exists, print 0.

inputFormat

The first line contains two integers \(n\) and \(T\): the number of elements and the target sum, respectively. The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output a single integer: the length of the longest contiguous subarray whose sum equals \(T\). If no such subarray exists, output 0.

## sample
5 3
1 -1 5 -2 3
4