Given a strictly increasing sequence of n
positive integers A(1) < A(2) < ... < A(n)
. We need to find the number of triangles with side lengths as 3
distinct elements of this sequence.
Since n <= 6000
, checking every possible combination is not fast enough. Is there any better algorithm? Thanks for any help.
My pseudocode:
for i from 0 till n - 2
for j from i+1 till n-1
for k from j+1 till n
if A[i] + A[j] > A[k] then count += 1
else break