A logistics dispatcher must repack a single cargo hold before a flight. The hold currently carries a shipment weighing exactly W kilograms, and airline regulations require every crate loaded for this shipment to weigh a positive, even whole number of kilograms, with no two crates sharing the same weight. The dispatcher wants to use as many crates as possible while using up the entire shipment weight exactly (the crate weights must sum to precisely W).
Given W, determine the maximum number of crates that can be used, and report one valid set of distinct positive even crate weights of that maximum size summing to exactly W. If more than one maximum-size set exists, report the one that is lexicographically smallest when its weights are listed in increasing order (informally: keep every crate as light as possible except the heaviest one, which absorbs whatever weight is left over).
If W is odd, no such split exists at all, since a sum of even numbers can never be odd — report that the shipment cannot be split.
A single line containing one integer, W.
If W is odd, print a single line containing -1. Otherwise print two lines:
Example 1
Input
8
Expected
2 2 6
Explanation
Three distinct positive even crates would need at least 2+4+6=12 kg, more than the 8 kg available, so the maximum is k=2 crates. The only pair of distinct positive even weights summing to 8 is {2, 6}, so the answer is 2 crates weighing 2 and 6 kg.
Example 2
Input
10
Expected
2 2 8
Explanation
The maximum is again k=2 crates (three would need at least 12 kg). Two different size-2 sets sum to 10: {2, 8} and {4, 6}. Listed in increasing order, [2, 8] is lexicographically smaller than [4, 6], so the required output is 2 and then 2 8, not 4 6.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →