#K44792. Counting Valid Triangle Triplets
Counting Valid Triangle Triplets
Counting Valid Triangle Triplets
Given an array of positive integers representing side lengths, your task is to count the number of triplets (i, j, k) that can form a triangle. A triplet can form a triangle if and only if for sorted sides (a \le b \le c), the triangle inequality (a + b > c) holds. In other words, you need to find the number of triplets such that (a+b>c) (in (\LaTeX): ()).
The input will be given through standard input, and the result should be printed to standard output as a single integer representing the count of valid triangle triplets.
inputFormat
The input starts with an integer (n) denoting the number of elements in the array, followed by (n) space-separated positive integers that represent the side lengths.
outputFormat
Output a single integer to standard output which is the total number of triplets that can form a triangle.## sample
4
2 2 3 4
3