#K7236. Equal Subset Partition

    ID: 33736 Type: Default 1000ms 256MiB

Equal Subset Partition

Equal Subset Partition

Given a list of positive integers, determine whether it is possible to partition the list into two non-empty subsequences such that the sum of the elements in each subsequence is equal.

In other words, check if there exists a way to split the list into two groups (both non-empty) where the sum of the elements in each group is the same. Using dynamic programming, you can compute whether a subset exists with sum equal to \(\frac{\text{total sum}}{2}\). Note that a valid partition must use all the numbers from the list.

Constraints:

  • \(1 \leq N \leq 10^5\), where \(N\) is the number of elements in the list.
  • \(1 \leq \text{each element} \leq 10^6\).

inputFormat

The first line of input contains an integer \(T\), the number of test cases.

For each test case, there is a single line containing \(N+1\) space-separated integers. The first integer is \(N\), the number of elements in the list, followed by \(N\) positive integers representing the list.

outputFormat

For each test case, output a single line containing \(YES\) if the list can be partitioned into two non-empty subsequences with equal sum, or \(NO\) otherwise.

## sample
2
5 1 5 11 5
4 1 2 3 5
YES

NO

</p>