#P10961. Equal Value Partition of Marbles

    ID: 13010 Type: Default 1000ms 256MiB

Equal Value Partition of Marbles

Equal Value Partition of Marbles

You are given (a_1, a_2, \dots, a_6) marbles, where there are (a_i) marbles of value (i) for (i = 1,2,\dots,6). The total number of marbles does not exceed (20000). Your task is to determine whether it is possible to partition all these marbles into two groups such that the sum of values in both groups are equal.

To illustrate, if you have one marble of each type (i.e. (a_1=a_2=\cdots=a_6=1)), the total value is (1+2+3+4+5+6=21), which is odd, hence it is impossible. On the other hand, if the total value is even, you must decide whether a subset of marbles exists with total value equal to half of the overall sum.

The problem can be solved by employing a dynamic programming approach similar to a bounded knapsack problem, often optimized using a binary (power-of-two) splitting technique.

inputFormat

The input consists of a single line containing 6 integers (a_1, a_2, \dots, a_6). These denote the number of marbles with values (1) through (6) respectively.

outputFormat

Output a single line: print “Yes” if it is possible to partition the marbles into two groups with equal total value, otherwise print “No”.

sample

1 1 1 1 1 1
Yes

</p>