PRBLEM IN NOTATRI

one of the practice problem have struct me off


here is the problem link i jst checked the solution and found that if we sort the array first check
as array is sorted
for(third=N-1;third>1;third–)
{
first=0;
second=third-1;
while(second>first)
{
if(len[first]+len[second]<len[third])
{
count+=second-first;
first++;
}
else
{
second–;
}
}
}
this part is the main logic for the given problem and this leads me in confusion how can we do this
count+=second-first;

sorting will help in terms of time. after sorting, start from the greatest value of length, if sum of smallest value and value lesser than(l[k-1]) taken value(l[k]), then add difference to count(cnt=cnt+l[k-1]-l[i]), because sum of all indices between those numbers, if considered particularly, will be lesser than taken value(l[k]). if sum of those two particular indices is greater than or equal to taken value(l[i]+l[j]>=l[k]), then increment the smallest index(i++). loop the aforementioned case for all index. voila.

//