#K95622. Subarray Sum Check

    ID: 38905 Type: Default 1000ms 256MiB

Subarray Sum Check

Subarray Sum Check

Given an array of integers and an integer \(k\), determine whether there exists a contiguous subarray whose sum is exactly \(k\). If such a subarray exists, output Yes; otherwise, output No.

The subarray should be non-empty and consist of consecutive elements from the array. The array may contain positive, negative, or zero values. An efficient solution can be achieved using the prefix sum technique.

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.

outputFormat

Output a single line containing either Yes if there exists a contiguous subarray that sums to (k), or No otherwise.## sample

5 9
1 2 3 4 5
Yes