#C9913. Balanced Array Partitioning
Balanced Array Partitioning
Balanced Array Partitioning
You are given an array of integers. Your task is to determine whether the array can be partitioned into two subsets such that the sum of the elements in both subsets is equal. In other words, check if there exists a subset whose sum is (\frac{S}{2}), where (S) is the total sum of the array. Note that if (S) is odd, the answer is definitely "NO".
For example, given the array [1, 2, 3, 4], the sum is 10 and we can form a subset [1, 4] (which sums to 5) and the remaining subset [2, 3] (also sums to 5), so the answer is "YES".
inputFormat
The input begins with a single integer (T) (the number of test cases). For each test case, the first line contains an integer (n) representing the number of elements in the array, followed by a line containing (n) space-separated integers.
outputFormat
For each test case, output a single line containing "YES" if the array can be partitioned into two subsets with equal sum, or "NO" otherwise.## sample
2
4
1 2 3 4
3
2 1 2
YES
NO
</p>