#C4782. Maximum Subarray Length

    ID: 48358 Type: Default 1000ms 256MiB

Maximum Subarray Length

Maximum Subarray Length

Given an array of integers and an integer \( k \), find the maximum length of a contiguous subarray whose elements sum up exactly to \( k \). If there is no such subarray, output 0.

A subarray is defined as a sequence of consecutive elements from the original array.

For example, if the array is [1, -1, 5, -2, 3] and \( k = 3 \), the maximum subarray that sums to 3 is [1, -1, 5, -2] which has a length of 4.

inputFormat

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

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

outputFormat

Print a single integer representing the maximum length of a subarray that sums exactly to \( k \). If no such subarray exists, output 0.

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