#C6483. Minimum Sticks to Form a Triangle

    ID: 50248 Type: Default 1000ms 256MiB

Minimum Sticks to Form a Triangle

Minimum Sticks to Form a Triangle

You are given an integer N and N stick lengths. Your task is to determine the minimum number of additional sticks you must add so that any three sticks from the collection (including the newly added ones) can form a triangle.

A triangle can be formed from three sticks with lengths a, b, and c (where a \le b \le c) if and only if:

[ a + b > c ]

If there are fewer than 3 sticks in the input, you are required to add enough sticks to have at least 3 sticks.

Note: The new stick(s) can have arbitrary lengths such that the triangle inequality holds for any triple chosen from the complete set. You only need to determine the minimum number of additional sticks required.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains an integer N (the number of sticks).
  • The second line contains N space-separated integers representing the lengths of the sticks.

outputFormat

Output a single integer to stdout which is the minimum number of additional sticks required.

Recall that three sticks with lengths a, b, c (with a \leq b \leq c) form a triangle if and only if:

[ a + b > c ]

sample

3
4 5 10
1

</p>