#C7466. Subarray Sum Existence

    ID: 51340 Type: Default 1000ms 256MiB

Subarray Sum Existence

Subarray Sum Existence

Problem Description:

Given an integer array of size n and an integer k, determine whether there exists a contiguous subarray whose sum is exactly k. Formally, find indices i and j (1 ≤ i ≤ j ≤ n) such that

(\sum_{t=i}^{j} a_t = k).

The input consists of two lines: the first contains the numbers n and k, and the second contains n space-separated integers. Output YES if such a subarray exists, otherwise output NO.

inputFormat

The input is read from standard input (stdin). The first line contains two space-separated integers n and k. The second line contains n space-separated integers representing the array.

outputFormat

Output to standard output (stdout) a single line containing either YES if there exists a contiguous subarray whose sum equals k, or NO otherwise.## sample

5 10
1 3 -2 5 7
YES

</p>