A remote coastal outpost operates three signal towers, each stocked with paired-launch flares used to send synchronized relay signals to passing ships. Sending one relay signal requires choosing two different towers that each still have at least one flare in stock, then firing one flare from each of the two chosen towers simultaneously (both towers' stock drops by exactly one). The pairing of towers may change freely from round to round, as long as both towers picked for that round currently have a flare available. The outpost commander wants to know the maximum total number of relay signals that can ever be sent, assuming towers are paired optimally.
A single line containing three space-separated integers a b c -- the number of flares initially stocked at Tower 1, Tower 2, and Tower 3 respectively.
Print a single integer: the maximum number of relay signals that can be sent in total.
Example 1
Input
2 4 6
Expected
6
Explanation
Sorted, the tower counts are 2, 4, 6. Since the two smaller counts (2 and 4) sum to 6, which does not exceed the largest count (6), every flare from the two smaller towers can be paired against the largest tower: 2 rounds pairing Tower1 with Tower3, then 4 rounds pairing Tower2 with Tower3, giving 6 relay signals total. After that only Tower3 has flares left, so no more rounds are possible, and the answer is 6.
Example 2
Input
3 3 3
Expected
4
Explanation
All three towers start with 3 flares. The two smaller counts (3 and 3) sum to 6, which exceeds the largest count (3), so the towers can be worked down almost evenly: total flares = 9, and the maximum achievable rounds is floor(9/2) = 4 (for example: Tower1&Tower2, Tower1&Tower3, Tower2&Tower3, Tower1&Tower2 again, leaving a single unpaired flare).
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 →