Gold Bars
InterviewTime limit2sMemory limit512 MB
Given three bar weights with an even total, decide whether the bars already split evenly, or which single bar to cut in two so the pieces divide equally.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Brute force, Array
- Solved
- No attempts yet
Problem
The highway robbers John and Bob robbed a caravan and got three gold bars as their loot. Deciding to split the loot fairly, John and Bob weighed the bars and found that they weigh , , and pounds, respectively.
Now John and Bob want to divide the bars so that each of them gets the same amount of gold. They would rather not saw the bars, but there is no way around it. After discussing the situation, they decided that if they can, they will split the loot as it is, and if they cannot, they will saw one bar into two pieces. They cannot saw two or all three bars.
Help John and Bob choose which bar to saw into two pieces and into which pieces to saw it, so that afterward they can divide the loot equally.
Input
The first line of the input contains three integers: , , and (, the sum of the bars' weights is even).
Output
If it is impossible to saw one bar in such a way that the gold can then be divided equally, output .
If John and Bob can already divide the gold equally, output .
Otherwise, on the first line output if the first bar should be sawed, if the second bar should be sawed, or if the third bar should be sawed. On the second line output two positive integers: the weights of the pieces into which the bar should be sawed. The two pieces must sum to the original weight of the bar. Since the total weight of the gold is even, the bar always needs to be sawed into pieces of integer weight. If there are several possible solutions, output any of them.