#K47772. Counting Special Triangle Triplets
Counting Special Triangle Triplets
Counting Special Triangle Triplets
You are given an array of n integers. Your task is to count the number of special triplets that can form a triangle. A triplet (a, b, c) is considered special if the following conditions (triangle inequalities) hold:
\(a + b > c\), \(b + c > a\), and \(c + a > b\).
Note that after sorting the array, the conditions reduce to checking only if \(a + b > c\) for every triplet (a, b, c) with indices i < j < k, because the ordering guarantees that the other inequalities hold automatically.
Your solution should read the input from standard input and write the result to standard output.
inputFormat
The input starts with an integer n (\(1 \leq n \leq 10^5\)), representing the number of elements in the array. The next line contains n space-separated integers, representing the elements of the array.
Example:
4 4 6 3 7
outputFormat
Output a single integer, which is the count of special triplets in the array that can form a triangle.
Example:
3## sample
4
4 6 3 7
3