Official algorithmic problem description and constraints.
Three friends gathered to play a few games of chess together.
In every game, two of them play against each other. The winner gets 2 points while the loser gets 0, and in case of a draw, both players get 1 point each. Note that the same pair of players could have played any non-negative number of times (possibly zero). It is also possible that no games were played at all.
You've been told that their scores after all the games were played were π1, π2 and π3. Additionally, it is guaranteed that π1β€π2β€π3 holds.
Find the maximum number of draws that could have happened and print it. If there isn't any way to obtain π1, π2 and π3 as a result of a non-negative number of games between the three players, print β1 instead.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.