Loading Now

makeTriangle

Mr Viet has three sticks of length a, b, c centimeters respectively. In one minute he can pick one arbitrary stick and increase its length by one centimeter. He is not allowed to break sticks.

What is the minimum number of minutes he needs to spend increasing the stick’s length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle’s sides (one stick for one side) and their endpoints should be located at triangle’s vertices.

Example

  • For a = 3, b = 4, c = 5, the output should be makeTriangle(a, b, c) = 0. Explain: Mr Viet can make a triangle without increasing the length of any sticks
  • For a = 2, b = 5, c = 3, the output should be makeTriangle(a, b, c) = 1. Explain: One way for Mr Viet to make triangle is to increase a by 1 to make a triangle with 3 edges of len 3,5,3

Input/Output

  • [execution time limit] 0.5 seconds 

  • [input] integer a, b, c

    Guaranteed constraints:
    0 ≤ a, b, c ≤ 10000.

  • [output] integer

    • the minimum number of minutes he needs

Post Comment

Contact