#C10541. Equal Sum Partition

    ID: 39758 Type: Default 1000ms 256MiB

Equal Sum Partition

Equal Sum Partition

You are given a list of integers. The input starts with an integer \(n\) representing the count of numbers that follow. Your task is to determine whether it is possible to partition the remaining \(n\) integers into two non-empty subsets such that the sum of the numbers in both subsets is equal.

If a valid partition exists, output Yes; otherwise, output No. If the count \(n\) does not match the number of integers provided, output the exact error message: The number of integers must match the given 'n'.

This problem can be approached using dynamic programming. In particular, if the total sum is even, you can check whether there is a subset whose sum is equal to half of the total sum. All formulas are represented in \( \LaTeX \) format; for example, if \(S\) is the total sum then the target sum for each partition is \(\frac{S}{2}\).

inputFormat

The input is given via stdin in the following format:

Line 1: An integer \(n\), representing the number of integers.
Line 2: \(n\) space-separated integers.

outputFormat

Output a single line to stdout with one of the following:

  • Yes — if it is possible to partition the list into two subsets with equal sum.
  • No — if it is not possible.
  • If the provided count does not match the number of integers given, output The number of integers must match the given 'n'.
## sample
4
1 5 11 5
Yes

</p>