#K79102. Equal Partition Problem

    ID: 35234 Type: Default 1000ms 256MiB

Equal Partition Problem

Equal Partition Problem

Given a list of integers, determine whether it is possible to partition the list into two sublists with equal sums. Formally, for a list (A = [a_1, a_2, \dots, a_n]), you need to decide if there exists a subset (S) such that (\sum_{a \in S} a = \frac{1}{2}\sum_{i=1}^{n} a_i). Each element must belong to exactly one of the two subsets, and all elements must be used. The answer should be printed to standard output (stdout) as either "YES" or "NO".

Constraints:

  • The input is provided through standard input (stdin).
  • The first line contains a single integer (n): the number of elements in the list.
  • The second line contains (n) space-separated integers.

Your task is to implement an algorithm using the dynamic programming approach to decide whether such a partition exists.

inputFormat

Input is read from standard input (stdin). The first line contains an integer (n), representing the number of elements. The second line contains (n) space-separated integers.

outputFormat

Output a single line to standard output (stdout) containing "YES" if it is possible to partition the list into two subsets with equal sum, otherwise output "NO".## sample

4
1 5 11 5
YES