title: Number of tuples
body: <p>I am given N numbers a[1..N] and 2 other integers L and H. How can I Count the number of tuples (i,j,k) satisfying i &lt; j &lt; k and L &lt;= a[i] + a[j] + a[k] &lt;= H.</p>
  
  <pre><code>1 &lt;= T &lt;= 100
  1 &lt;= N &lt;= 1000
  1 &lt;= L &lt;= H &lt;= 1000000
  1 &lt;= a[i] &lt;= 1000000 
  </code></pre>
  
  <p>PS: Need Better Solution than N2logn</p>