NOTATRI - Not a Triangle

You have N (3 ≤ N ≤ 2,000) wooden sticks, which are labeled from 1 to N. The i-th stick has a length of Li (1 ≤ Li ≤ 1,000,000). Your friend has challenged you to a simple game: you will pick three sticks at random, and if your friend can form a triangle with them (degenerate triangles included), he wins; otherwise, you win. You are not sure if your friend is trying to trick you, so you would like to determine your chances of winning by computing the number of ways you could choose three sticks (regardless of order) such that it is impossible to form a triangle with them.


The input file consists of multiple test cases. Each test case starts with the single integer N, followed by a line with the integers L1, ..., LN. The input is terminated with N = 0, which should not be processed.


For each test case, output a single line containing the number of triples.


4 2 10
1 2 3
5 2 9 6


For the first test case, 4 + 2 < 10, so you will win with the one available triple. For the second case, 1 + 2 is equal to 3; since degenerate triangles are allowed, the answer is 0.

hide comments
Alexander Shlemov: 2012-08-23 17:55:21

Please, note bounds of the number of subtest in one test file.

Last edit: 2012-08-23 18:38:03
saket diwakar: 2012-07-03 05:51:48

ufff....a silly mistake caused me 3 TLE's....

npsabari: 2012-06-02 19:15:51

For test cases :
8 8 2 2 3
is 6 is the correct answer ( considering the two 8's ans similarly two 2's to be distinct ) or 2 ( considering them to be identical ) ?? help!!

Considered it to be different and got AC!

Last edit: 2012-06-02 19:51:46
accept: 2012-06-01 02:04:18

nice que...

Grandmaster: 2011-06-25 06:04:16

what is the preferred complexity for this code ???

Added by:Neal Wu
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO