#K15711. Contiguous Subarray Sum

    ID: 24418 Type: Default 1000ms 256MiB

Contiguous Subarray Sum

Contiguous Subarray Sum

Given an integer \(K\) and an array of integers, you are to determine whether there exists a contiguous subarray whose sum is exactly \(K\). If such a subarray exists, output Y; otherwise, output N. This problem is a classic application of prefix sum techniques combined with hash-based lookup.

For instance, if \(K=15\) and the array is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], there exists a subarray [1,2,3,4,5] that sums to \(15\), so the output will be Y. Conversely, if \(K=100\) for the same array, no contiguous subarray meets the requirement, and the output will be N.

inputFormat

The input is read from standard input (stdin). The first line contains two integers: \(K\) (the target sum) and \(n\) (the number of elements in the array). The second line contains \(n\) space-separated integers, which may include negative numbers.

outputFormat

Output a single character to standard output (stdout): Y if a contiguous subarray summing to \(K\) exists, and N otherwise.

## sample
15
10
1 2 3 4 5 6 7 8 9 10
Y

</p>