#C8415. Partition Equal Subset Sum
Partition Equal Subset Sum
Partition Equal Subset Sum
You are given an array of non-negative integers. Your task is to determine whether you can partition the array into two subsets such that the sum of the elements in both subsets is equal.
More formally, given an array A of size n, find if there exists a subset S such that:
\( \sum_{a \in S} a = \frac{1}{2}\sum_{a \in A} a \)
If the total sum is odd, then it is impossible to split the array into two equal parts.
Example:
- For A = [1, 5, 11, 5], the answer is YES because the array can be partitioned as [1, 5, 5] and [11], both summing to 11.
- For A = [1, 2, 3, 5], the answer is NO.
inputFormat
The first line contains a single integer n representing the number of elements in the array.
The second line contains n non-negative integers separated by spaces.
outputFormat
Output a single line containing YES
if the array can be partitioned into two subsets with equal sum, or NO
otherwise.
4
1 5 11 5
YES