#K2356. Equal Weight Partition

    ID: 24718 Type: Default 1000ms 256MiB

Equal Weight Partition

Equal Weight Partition

You are given a collection of weights. Your task is to determine whether these weights can be partitioned into two groups such that the sum of the weights in each group is equal.

The problem can be mathematically expressed as follows: Given a sequence of weights \(w_1, w_2, \dots, w_n\), decide if there exists a subset of these weights whose sum equals \(\frac{1}{2}\) of the total sum. That is, if the total sum \(S = \sum_{i=1}^{n} w_i\) is even, you need to check if there is a subset with sum \(\frac{S}{2}\). If \(S\) is odd, such a partition is impossible.

This problem is a classic example of the subset sum problem and can be solved efficiently using dynamic programming.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  • The first line contains an integer \(n\) (the number of weights).
  • The second line contains \(n\) space-separated integers representing the weights.

It is guaranteed that \(n \geq 1\) and each weight is a positive integer.

outputFormat

Output a single line to standard output (stdout):

  • "YES" if the weights can be partitioned into two groups with equal sum.
  • "NO" otherwise.
## sample
4
1 5 11 5
YES

</p>