#K57862. Contiguous Subarray Sum

    ID: 30515 Type: Default 1000ms 256MiB

Contiguous Subarray Sum

Contiguous Subarray Sum

You are given an array of integers and an integer target. Your task is to determine whether there exists a non-empty contiguous subarray whose sum is exactly equal to the target.

In other words, given an array (a_1, a_2, \dots, a_n) and an integer (T), determine if there exist indices (i) and (j) with (1 \le i \le j \le n) such that (\sum_{k=i}^{j} a_k = T). This problem may be solved efficiently using prefix sums and checking if (S_{j} - S_{i-1} = T), where (S_k) denotes the sum of the first (k) elements (with (S_0=0)).

inputFormat

The input is read from standard input. The first line contains a single integer (T) indicating the number of test cases. Each test case consists of three lines:
1. An integer (n) representing the number of elements in the array.
2. (n) space-separated integers representing the array elements.
3. An integer (target) representing the desired sum of a contiguous subarray.

outputFormat

For each test case, output a single line to standard output containing either "YES" if there exists at least one contiguous subarray whose sum equals the target, or "NO" otherwise.## sample

3
5
1 2 3 4 5
7
3
3 2 7
10
8
1 2 3 4 5 6 7 8
15
YES

NO YES

</p>