title: How should you avoid SIGABRT errors in C++?
body: <p>I was trying to write the following program for a programming contest (already over). However, I keep getting the SIGABRT error. I make sure to empty all the containers before I run the next test case. What should I check? </p>
  
  <p>This is how I am implementing the code:
  <a href="http://discuss.codechef.com/questions/29659/lowsum-editorial" rel="nofollow">http://discuss.codechef.com/questions/29659/lowsum-editorial</a></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;algorithm&gt;
  #include&lt;queue&gt;
  #include&lt;vector&gt;
  
  using namespace std;
  
  class compare
  {
  public:
      bool operator()(int a, int b)
      {
          return a&gt;b;
      }
  };
  
  int main()
  {
      int T,K,Q;
      vector&lt;int&gt; A,B,q,nsum;
      priority_queue&lt;int, vector&lt;int&gt; , compare&gt; PQ;      //min PQ
      scanf("%d",&amp;T);
  
  while(T--)
  {
      scanf("%d %d",&amp;K,&amp;Q);
  
      A.resize(K);
      B.resize(K);
      q.resize(Q);
  
      for(int i= 0;i&lt;K;++i)
          scanf("%d",&amp;A[i]);
  
      for(int i=0;i&lt;K;++i)
          scanf("%d",&amp;B[i]);
  
      int max_q=0;
  
      for(int i=0;i&lt;Q;++i)
      {
         scanf("%d",&amp;q[i]);
         if(q[i]&gt;max_q)
          max_q=q[i];
      }
  
      sort(A.begin(),A.end());
      sort(B.begin(),B.end());
  
      while(!PQ.empty())
          PQ.pop();
  
      int j=0;
  
      while(max_q &gt; 0 &amp;&amp; j &lt; K)
      {
          for(int i=0;i&lt;K;++i)
              PQ.push(A[i]+B[j]);
  
          max_q--;
          j++;                        //next element of B[]
      }
  
      while(!PQ.empty())
      {
          nsum.push_back(PQ.top());
          PQ.pop();
      }
  
      for(int j=0;j&lt;Q;++j)
         printf("%d\n",nsum[q[j]-1]);
  
      nsum.clear();
  }
  }
  </code></pre>