#K56727. Subarray Sum Equals K

    ID: 30263 Type: Default 1000ms 256MiB

Subarray Sum Equals K

Subarray Sum Equals K

Given an integer array (a) of length (n) and an integer (k), determine whether there exists a contiguous subarray whose elements sum to (k). In other words, check if there are indices (i) and (j) with (0 \leq i \leq j < n) such that

[ \sum_{t=i}^{j} a_t = k ]

If such a subarray exists, output YES, otherwise output NO.

This problem tests your understanding of prefix sums and subarray summing techniques. Please note that the solution should read from standard input and write to standard output.

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 (a).

outputFormat

Output a single line: YES if there exists a contiguous subarray with sum equal to (k), otherwise NO.## sample

5 8
1 2 3 4 -1
YES

</p>