#K7931. Perfect Weight Balance
Perfect Weight Balance
Perfect Weight Balance
You are given a list of positive integers representing weights. Your task is to determine if the weights can be split into two groups such that the sum of the weights in both groups is equal. In other words, given weights \(w_1, w_2, \dots, w_n\), check if there exists a subset \(S\) so that
[ \sum_{i \in S} w_i = \frac{1}{2} \sum_{i=1}^n w_i, ]
If the total weight is odd, it is impossible to split them evenly. The input consists of multiple test cases. For each test case, first an integer \(N\) is given, which is the number of weights, followed by a line with \(N\) space-separated integers. A test case with \(N = 0\) indicates the end of input.
inputFormat
The input will contain multiple test cases. For each test case:
- The first line contains a single integer \(N\) (\(N \ge 0\)). \(N = 0\) indicates termination of the input.
- If \(N > 0\), the next line contains \(N\) space-separated positive integers representing the weights.
All test cases are read from standard input.
outputFormat
For each test case, output a single line containing "YES" if it is possible to partition the weights into two groups with equal sum, or "NO" otherwise. The output should be written to standard output, one result per test case.
## sample3
1 2 3
0
YES
</p>