#C6573. Partition Equal Subset Sum
Partition Equal Subset Sum
Partition Equal Subset Sum
You are given an array of positive 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.
Let \( S \) be the sum of all elements in the array. A necessary condition for the existence of such a partition is that \( S \) is even. That is, \( S = 2 \times T \) for some integer \( T \). The problem then reduces to finding a subset with sum \( T \).
This problem can be solved efficiently using dynamic programming (DP) by determining if a subset with sum \( T = \frac{S}{2} \) exists. If it does, output YES
; otherwise, output NO
.
inputFormat
The first line of input contains a single integer \( n \) (the number of elements in the array). The second line contains \( n \) space-separated positive integers representing the elements of the array.
Example:
4 1 5 11 5
outputFormat
Output a single line containing either YES
if the array can be partitioned into two subsets with equal sum, or NO
otherwise.
Example:
YES## sample
4
1 5 11 5
YES
</p>