#K15631. Equal Sum Partition
Equal Sum Partition
Equal Sum Partition
You are given a list of positive integers. Your task is to determine whether the list can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Formally, given an array \( nums \), decide if there exists two disjoint subsets \( A \) and \( B \) such that \( A \cup B = nums \) and \( \sum_{a \in A}a = \sum_{b \in B}b \). If such a partition exists, output YES
; otherwise, output NO
.
Hint: The total sum must be even to allow an equal partition. Use a dynamic programming approach to check if a subset with sum equal to half of the total sum exists.
inputFormat
The input is read from stdin
and consists of multiple lines. The first line contains a single integer \( T \) representing the number of test cases. Each of the following \( T \) lines contains a space-separated list of positive integers.
outputFormat
For each test case, output a single line to stdout
that is either YES
if the list can be partitioned into two subsets with equal sum, or NO
otherwise.
2
1 5 11 5
1 2 3 5
YES
NO
</p>