#K36372. Subarray Sum Existence

    ID: 25740 Type: Default 1000ms 256MiB

Subarray Sum Existence

Subarray Sum Existence

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

\[ A[i] + A[i+1] + \cdots + A[j] = M \]

If such a subarray exists, output True; otherwise, output False.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains two space-separated integers \(N\) and \(M\) — where \(N\) is the number of array elements and \(M\) is the target sum.
  • The second line contains \(N\) space-separated integers representing the elements of the array \(A\). (If \(N = 0\), the second line will be empty.)

outputFormat

Output a single line to standard output (stdout) with either True or False indicating whether there exists a contiguous subarray whose sum equals \(M\).

## sample
5 12
1 2 3 7 5
True