#K7586. Equal Sum Partition Problem

    ID: 34513 Type: Default 1000ms 256MiB

Equal Sum Partition Problem

Equal Sum Partition Problem

You are given a set of n integers and an extra integer parameter k (which is not used in the decision). Your task is to determine if it is possible to partition the set into two subsets such that the sum of the elements in both subsets is equal.

Formally, let \(S = \{a_1, a_2, \dots, a_n\}\) be the set with total sum \(\text{total} = \sum_{i=1}^{n} a_i\). You need to decide whether there exists a subset \(S' \subseteq S\) such that:

[ \sum_{a \in S'} a = \frac{\text{total}}{2} ]

If \(\text{total}\) is odd, then such a partition is impossible. Otherwise, use a dynamic programming approach to determine if a subset exists with the target sum \(\frac{\text{total}}{2}\).

Input is given via standard input and output via standard output.

inputFormat

The first line of input contains two integers: n (the number of elements) and k (an extra parameter which is not used in the computation).

The second line contains n space-separated integers representing the elements of the set.

Example:

5 10
1 2 3 4 6

outputFormat

Output a single line with YES if it is possible to partition the set into two subsets with equal sum, or NO otherwise.

Example:

YES
## sample
5 10
1 2 3 4 6
YES