title: reverse iteration of map in c++ missing out the first element
body: <p>I have a code where I am reverse iterating a map in C++. For n pairs in map, sometimes the map prints out n pairs, sometimes n-1 pairs.
  for test case   </p>
  
  <pre><code>4 2    
  2 1  
  3 5  
  2 3  
  1 5 
  </code></pre>
  
  <p>it prints 4 hi's, for the next case 3 hi's  </p>
  
  <pre><code>4 1  
  0 2  
  0 3  
  3 5  
  0 6  
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>include cmath, cstdio, vector, iostream, map, algorithm, using namespace std;
  
  int main() {
      int n,f;
      cin &gt;&gt; n &gt;&gt; f;
      int k[n],l[n],dif[n];
      map&lt;int,int&gt; m;
      map&lt;int,int&gt;::reverse_iterator it;
  
      for (int i=0;i&lt;n;i++){
          scanf("%d %d\n",&amp;k[i],&amp;l[i]);
          dif[i] = l[i]-k[i];
          m.insert(make_pair(dif[i],l[i]));
      }
  
      int a = 0;
      int sum = 0;
  
      for(it = m.rbegin(); it != m.rend(); ++it ) {
          cout &lt;&lt; "hi" &lt;&lt; endl;
          int article = it-&gt;second - it-&gt;first;
          int people = it-&gt;second;
  
          if (a &lt; f and article!=0){
              a++;
  
              if (2*article &gt; people){
                  sum = sum + people;
              } else {
                  sum = sum + (2*article);
              }
          } else {
  
              if (article &gt; people){
                  sum = sum + people;
              } else {
                  sum = sum + article;
              }
          }
      }
  
      cout &lt;&lt; sum;
      return 0;
  }
  </code></pre>