title: Finding the number of elements less than or equal to k in a multiset
body: <p>I have a multiset, implemented as follows:</p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  multiset &lt;int&gt; M;
  
  int numunder(int k){
      /*this function must return the number of elements smaller than or equal to k
      in M (taking multiplicity into account).
      */
  }
  </code></pre>
  
  <p>At first I thought I could just return M.upper_bound(k)-M.begin()+1. Unfortunately it seems we cannot subtract pointers like that. We ended up having to implement an AVLNodes structure. Is there a way to get this to work taking advantage of the c++ std?</p>