#C11559. Counting Valid Triangles
Counting Valid Triangles
Counting Valid Triangles
You are given several test cases. In each test case, you are provided with an array of positive integers representing potential side lengths. Your task is to count the number of triplets ( (a, b, c) ) that can form a valid triangle. A triangle is valid if and only if the following inequality holds:
( a + b > c )
where the side lengths are considered in non-decreasing order. Note that the input for each test case contains an extra integer which is a placeholder and can be ignored. Your program should read input from standard input and print the answer for each test case on a new line to standard output.
inputFormat
The first line of input contains an integer ( T ) representing the number of test cases. For each test case, the first line contains two integers ( n ) and a placeholder integer (which is not used). The second line contains ( n ) space-separated integers representing the side lengths.
outputFormat
For each test case, output a single integer on a new line representing the number of triplets that can form a triangle.## sample
2
4 7
2 2 3 4
5 10
1 2 3 4 5
3
3
</p>