#K3241. Subarray Sum Problem

    ID: 24915 Type: Default 1000ms 256MiB

Subarray Sum Problem

Subarray Sum Problem

Given an array of integers and a target sum \(X\), determine if there exists a contiguous subarray whose elements sum exactly to \(X\). In other words, you need to check whether there exist indices \(i\) and \(j\) (with \(0 \le i \le j < N\)) such that

[ \sum_{k=i}^{j} a_k = X ]

If such a subarray is found, output YES; otherwise, output NO.

inputFormat

The input is given via standard input (stdin). The first line contains two integers: (N) (the number of elements in the array) and (X) (the target sum), separated by a space. The second line contains (N) space-separated integers representing the array elements.

outputFormat

The output should be printed to standard output (stdout) as a single line containing either YES if a contiguous subarray summing to (X) exists, or NO otherwise.## sample

5 15
1 2 3 7 5
YES