#C3525. Longest Contiguous Subarray Sum

    ID: 46962 Type: Default 1000ms 256MiB

Longest Contiguous Subarray Sum

Longest Contiguous Subarray Sum

Given an array of integers and a target integer, your task is to find the length of the longest contiguous subarray whose sum equals the target.

If no such subarray exists, output 0.

More formally, for an array \(A\) of length \(n\) and an integer \(T\), find the maximum length \(L\) such that there exist indices \(i\) and \(j\) with \(0 \leq i \leq j < n\) for which: $$\sum_{k=i}^{j}A[k]=T.$$

inputFormat

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 representing the array elements.

outputFormat

Output a single integer, the length of the longest contiguous subarray that sums to \(t\). If no such subarray exists, output 0.

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