#K79857. Equal Sum Partition of Array

    ID: 35401 Type: Default 1000ms 256MiB

Equal Sum Partition of Array

Equal Sum Partition of Array

You are given an array of n integers. Your task is to determine whether it is possible to split the array into exactly two non-empty contiguous segments such that the sum of the elements of the first segment is equal to the sum of the elements of the second segment.

Formally, find an index i (1 ≤ i < n) such that:

j=1iaj=j=i+1naj\sum_{j=1}^{i} a_j = \sum_{j=i+1}^{n} a_j

If such an index exists, output YES; otherwise, output NO.

Note: The partition must split the array into two non-empty parts.

inputFormat

The input is given via standard input (stdin) and consists of multiple test cases. The first line contains an integer T representing the number of test cases. Each test case is described as follows:

  1. The first line of a test case contains an integer n – the number of elements in the array.
  2. The second line contains n integers separated by spaces, representing the array elements.

It is guaranteed that 2 ≤ n for each test case.

outputFormat

For each test case, output a single line that contains either YES if it is possible to partition the array as described, or NO otherwise. The answer for each test case should be printed on a new line.

## sample
5
4
1 2 3 4
5
1 1 1 1 2
3
3 3 3
2
0 0
6
1 2 3 4 5 6
NO

YES NO YES NO

</p>