title: sort function C++ segmentation fault
body: <p>In this code, for vector size, n >=32767, it gives segmentation fault, but upto 32766, it runs fine. What could be the error? This is full code.</p>
  
  <pre><code>#include&lt;cstdio&gt;
  #include&lt;cstring&gt;
  #include&lt;cmath&gt;
  #include&lt;queue&gt;
  #include&lt;utility&gt;
  #include&lt;algorithm&gt;
  #include&lt;sys/time.h&gt;
  using namespace std;
  #define MAX 100000
  
  bool compare(pair&lt;int,int&gt; p1,pair&lt;int,int&gt; p2) {
      if(p1.second &lt; p2.second)
          return 1;
      else if(p1.second &gt; p2.second)
          return 0;
      if(p1.first &lt;= p2.first)
          return 1;
      else
          return 0;
  }
  
  int main() {
      freopen("randomin.txt","r",stdin);
      int n;
      scanf("%d",&amp;n);
      vector&lt; pair&lt;int,int&gt; &gt; p(n);
      for(int i=0;i&lt;n;i++)
          scanf("%d%d",&amp;p[i].first,&amp;p[i].second);
      **printf("%d\n",(int)p.max_size()); // prints 536870911**
      sort(p.begin(),p.begin()+n,compare);
  
      //for(int i=0;i&lt;n;i++)
          //printf("%d %d\n",p[i].first,p[i].second);
          printf("%.6f\n",(p[n-1].second+p[n-2].second)/(20.0+p[n-1].first+p[n-2].first));
  
      return 0;
  }
  </code></pre>