King's Inspection
InterviewTime limit1sMemory limit512 MB
Given three coin counts, each second you add one coin to two different chests; find the minimum number of seconds to make all three equal.
- Level
Medium4 of 10
- Topics
- Greedy, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
The treasury of the Far Far Away Kingdom is in trouble: the King is coming with an inspection. The King is known to like order, so the chief treasurer needs to put the three chests that store the Kingdom's gold coins in order. He looked into the chests and found that they contain , , and coins, respectively. But the King would certainly like the chests to contain the same number of coins each.
To make the number of coins equal, the chief treasurer started adding coins with both hands. Each second he chooses two distinct chests and adds one more coin to each of them.
Help the chief treasurer find how many seconds he needs to make the number of coins in the chests equal.
Input
The input contains three lines.
The first line contains an integer .
The second line contains an integer .
The third line contains an integer ().
Output
Output one integer: the minimum number of seconds the chief treasurer needs to make the number of coins in the chests equal.
Notes
One optimal strategy for the first test is the following: first, add a coin to chests 1 and 3, then add a coin to chests 1 and 2, and again to chests 1 and 2.
All chests in the second test already contain an equal number of coins.