#C1834. Equal Sum Disjoint Subsets
Equal Sum Disjoint Subsets
Equal Sum Disjoint Subsets
You are given an array \(a\) of \(n\) integers. Your task is to determine whether there exist two disjoint non-empty subsets of \(a\) that have the same sum.
A subset of the array is defined as any selection of elements (order does not matter) in which each element appears at most once. Two subsets are disjoint if they do not share any common elements.
For example, given \(a = [1,2,3,4]\), one valid solution is the two subsets \(\{1,4\}\) and \(\{2,3\}\) since both sum to 5 and they have no elements in common.
Determine if such disjoint subsets exist. If they do, output YES
, otherwise output NO
.
inputFormat
The first line contains an integer \(n\) — the number of elements in the array. The second line contains \(n\) space-separated integers, which represent the array \(a\).
\(1 \le n \le 20\) (the constraints are small enough for an exponential solution).
outputFormat
Output a single line with the word YES
if there exist two disjoint non-empty subsets with equal sum, otherwise output NO
.
4
1 2 3 4
YES
</p>