#C5719. Maximum Perimeter of Triangle
Maximum Perimeter of Triangle
Maximum Perimeter of Triangle
You are given a collection of sticks. Your task is to determine the maximum possible perimeter of a triangle that can be formed using any three of these sticks. For a valid triangle with sides \(a\), \(b\), and \(c\), the triangle inequality must hold: \(a < b + c\), \(b < a + c\), and \(c < a + b\). If no valid triangle can be formed, output \(-1\).
Input Format: The first line contains an integer \(n\) denoting the number of sticks. The second line contains \(n\) space-separated integers representing the lengths of the sticks.
Output Format: Output a single integer denoting the maximum perimeter of a triangle that can be formed, or \(-1\) if no triangle exists.
inputFormat
The input begins with an integer \(n\), the number of sticks. The next line contains \(n\) space-separated integers \(l_1, l_2, \dots, l_n\) representing the lengths of the sticks.
outputFormat
Print a single integer: the maximum possible perimeter of a triangle formed by any three sticks, or \(-1\) if no valid triangle can be formed.
## sample5
2 3 4 5 10
12
</p>