title: Why this sort() will change value of the vector?
body: <p>I was trying to solve this problem: <a href="https://www.hackerrank.com/challenges/board-cutting" rel="nofollow">https://www.hackerrank.com/challenges/board-cutting</a></p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;cstdio&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #define LL long long
  #define M 1000000007LL
  using namespace std;
  
  int T,n,m;
  LL cc;
  
  struct Cut{
      int dir;
      LL cost;
      Cut(const int&amp; dir, const LL&amp; cost): dir(dir), cost(cost){}
      Cut(){}
  
      bool operator&lt;(const Cut&amp; cut) const
      {   
          return this-&gt;cost &gt;= cut.cost;
      } 
  };
  
  vector&lt;Cut&gt; c;
  
  int main() {
      cin &gt;&gt; T;
      while(T--){
          cin &gt;&gt; n &gt;&gt; m;
          LL ans = 0, cnt[2] = {0};
          c.clear();
  
          for(int i=0; i&lt;n-1; i++) cin &gt;&gt; cc, c.push_back(Cut(0, cc));
          for(int i=0; i&lt;m-1;i++) cin &gt;&gt; cc, c.push_back(Cut(1, cc));
  
  
          sort(c.begin(), c.end());
  
  
          for(int i=0; i&lt;c.size(); i++){
              cout &lt;&lt; c[i].cost &lt;&lt; endl;
          }
          cout &lt;&lt; "END" &lt;&lt; endl;
  
          for(Cut x : c){
              (ans += x.cost*(1+cnt[!x.dir]))%=M;
              cnt[x.dir]++;
          }
  
          cout &lt;&lt; ans &lt;&lt; endl;   
      }
      return 0;
  }
  </code></pre>
  
  <p>I have such a C++ code which consumes input from std I/O</p>
  
  <p>I have added a loop to output the vector objects' cost property.
  Now for the following input:</p>
  
  <pre><code>2
  83 99
  24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
  34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
  99 49
  11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
  61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
  </code></pre>
  
  <p>The second test case does not have cost with 24 (only the first test case has 24)
  But if you run the code, you will find that the vector contains Cut object with cost 24 after sort()!</p>
  
  <p>Why is this happening and how can I solve it?</p>
  
  <p><strong>(The above sample input is hackerrank official test case input for this problem, so its correctness is assured)</strong></p>