Barbells
Time limit2sMemory limit512 MB
Given up to 14 bars and 14 plates, find every total weight obtainable by putting plates on both sides of one bar so that the two sides balance.
- Level
Medium6 of 10
- Topics
- Brute force, Hash map, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
The gym down the street has bars and plates. To prepare a weight for lifting you pick one bar and load plates onto its two sides. The set of plates on a side may be empty. For safety the two sides must balance: their plate weights have to sum to the same value. The plates on one side may differ from the plates on the other side, as long as the two sums are equal.
Each plate can be used at most once, and any plate may be left unused. The lifting weight is the weight of the bar plus the weight of all plates loaded on both sides. Find every weight that is available for lifting.

Input
The first line contains two integers and (), the number of bars and the number of plates. Each of the next lines contains one integer (), the weight of a bar. Each of the following lines contains one integer (), the weight of a plate.
Output
Print every available lifting weight in increasing order, one per line. Do not print the same weight twice.