#K80082. Maximum Triangle Perimeter
Maximum Triangle Perimeter
Maximum Triangle Perimeter
Given a set of stick lengths, your task is to determine the maximum perimeter of a triangle that can be formed using any three sticks. A triangle is valid if it satisfies the triangle inequality: \(a < b + c\), \(b < a + c\), and \(c < a + b\). If no valid triangle can be formed, output 0.
The challenge can be solved by first sorting the sticks in descending order and then checking consecutive triples for the triangle condition.
inputFormat
The input begins with an integer \(T\) representing the number of test cases. Each test case 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
For each test case, output a single line containing the maximum perimeter of a valid triangle that can be formed. If no valid triangle is possible, output 0.
## sample1
3
2 1 2
5
</p>