Stick Work

3.5

11 votes
Easy-Medium
Problem

You are given with N sticks. The height of each stick is given to you. Your task is to find out in how many ways you can select three sticks such that they don’t form a valid triangle.

INPUT The first line of input contains T (denoting the number of test cases).First line of each test case contains N,followed by a line with the N integers “Ai” (denoting the height of ith stick).

OUTPUT For each test case, output a single line containing the number of triples.
Constraints:- T<210 , N<2500

Example

INPUT
2
3
4 2 10
4
5 2 9 6

OUTPUT
1
2
Explaination
Test case #1 : There is only one way of selecting three sticks {4 , 2 , 10} and these sticks do not form a valid triangle.
Test case #2 : There are two ways of selecting three sticks that do not form a valid triangle {5 , 2 , 9} and {2 , 9 , 6}. Problem author ;- Mohit jain

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?