#C2379. Equal Sum Contiguous Subsequences

    ID: 45688 Type: Default 1000ms 256MiB

Equal Sum Contiguous Subsequences

Equal Sum Contiguous Subsequences

In this problem, you are given a sequence of integers. Your task is to determine whether there exists a position to split the sequence into two non-empty contiguous subsequences such that the sums of the elements in each part are equal. More formally, given an array (a_1, a_2, \dots, a_n), check whether there exists an index (i) (with (1 \le i < n)) such that [ \sum_{j=1}^{i} a_j = \sum_{j=i+1}^{n} a_j, ] If such an index exists, print YES; otherwise, print NO.

Note: The sequence may include negative numbers as well. Ensure that both parts of the split are non-empty.

inputFormat

The first line contains an integer (T) denoting the number of test cases. Each test case is described as follows:

  • The first integer \(n\) represents the length of the sequence.
  • Then \(n\) space-separated integers follow, representing the sequence itself.
Input is read from standard input (stdin).

outputFormat

For each test case, output a single line containing either YES if there exists a position where the sequence can be split into two contiguous subsequences with equal sum, or NO if it is impossible. The output is written to standard output (stdout).## sample

3
5 1 2 3 4 5
4 4 3 2 1
4 5 5 0 10
NO

NO YES

</p>