#K61157. Equal Subset Partitioning
Equal Subset Partitioning
Equal Subset Partitioning
Given an array of integers arr, determine whether it is possible to partition the array into two subsets such that the sum of the elements in both subsets is equal.
Let \(S = \sum_{i=1}^{n} a_i\) be the total sum of the array. A valid partition can only exist if \(S\) is even. In that case, the problem reduces to finding a subset of \(arr\) whose sum is \(\frac{S}{2}\). If such a subset exists, print Yes
, otherwise print No
.
inputFormat
The input is given from stdin in the following format:
- The first line contains a single integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers, which are the elements of the array.
outputFormat
Output to stdout a single line containing Yes
if there exists a partition of the array into two subsets with equal sum, and No
otherwise.
4
1 5 11 5
Yes