#K8491. Split Array into Two Subsequences with Equal Sum
Split Array into Two Subsequences with Equal Sum
Split Array into Two Subsequences with Equal Sum
You are given an array of integers. Your task is to determine whether it is possible to partition the array into two non-empty subsequences such that the sum of the elements in both subsequences is equal.
In other words, let \(S\) be the sum of all elements in the array. You need to decide if there exists a non-empty proper subset \(A\) of the array such that
[ \sum_{x \in A} x = \frac{S}{2} ]
Note that if \(S\) is odd then it is impossible to partition the array into two parts with equal sum. The two subsequences do not need to be contiguous, but together they must partition the entire set of elements.
Input Format: The input is given via standard input. The first line contains an integer \(t\) representing the number of test cases. For each test case, the first line contains an integer \(n\), the size of the array. The next line contains \(n\) space-separated integers representing the array elements.
Output Format: For each test case, print a single line containing YES
if it is possible to split the array into two subsequences with equal sum, or NO
otherwise.
inputFormat
The first line of input contains a single integer \(t\) (the number of test cases). Each test case is described by two lines:
- The first line contains an integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers.
outputFormat
For each test case, output a single line. The line should contain YES
if the array can be partitioned into two non-empty subsequences with equal sum, or NO
otherwise.
4
4
1 2 3 4
3
1 1 1
5
1 2 3 6
6
1 -1 2 -2 3 -3
YES
NO
YES
YES
</p>