title: finding maximal element in c++ map
body: <p>We have <code>C++ map&lt;double, class_name&gt;</code> <code>mymap</code>.
  We are given some double <code>X</code>. </p>
  
  <p>Task is to find value in mymap associated with the largest key that is less than equal to <code>X</code>. If <code>X</code> is less than lowest key of <code>mymap</code> return some default value declared before.</p>
  
  <p>My approach is iterate through <code>mymap</code> and find maximal key that is less than or equal to <code>X</code></p>
  
  <pre><code>double max = std::numeric_limits&lt;double&gt;::lowest();
  
  for ( auto ii=mymap.begin(); ii!=mymap.end(); ++ii ) {
    if (
      (*ii).first &lt;= value &amp;&amp; 
      (*ii).first &gt; max
    ) {
      max = (*ii).first;
    }
  }
  
  if ( max==std::numeric_limits&lt;double&gt;::lowest() )
      return defaultValue;
  
  return colorset.find(max)-&gt;second;
  </code></pre>
  
  <p>Is this correct approach?
  I am new at c++ map, so I want to know may be there is a better way of implementing this task?</p>
  
  <p>I guess proposed algorithm's complexity is <code>O(n)</code>, probably there is a way to find it <code>O(log n)</code> or with even better complexity or memory allocation?</p>