Counting pairs of integers whose sum is less than a given threshold
A better algorithm

Your current algorithm has a worst case time of \$O(n^2)\$, when the list is half filled with zeroes, and half filled with k/2.  You can solve the problem in \$O(n \log n)\$ time by doing the following:


Sort the input.
Use two indices, one starting at the low end and one starting at the high end.  Call these indices i and j.
For each i, walk j down until a[i] + a[j] &lt; k.  When this happens, add j-i to the solution count, and increment i.  Do not reset j.
Stop when i &gt;= j.


Steps 2-4 solve the problem in \$O(n)\$ time, but the sort in step 1 takes \$O(n \log n)\$ time.  Here is a code snippet to illustrate the key part:

for (int i=0, j=len-1; i &lt; j; i++) {
    while (j &gt; i &amp;&amp; a[i]+a[j] &gt;= k)
        j--;
    count += j - i;
}