title: Array of vectors and variable array
body: <p>Could anyone please help me? I was doing <a href="https://www.hackerrank.com/challenges/variable-sized-arrays/problem" rel="nofollow noreferrer">a problem on HackerRank</a> and there was this problem using vectors. But I am getting segmentation faults.</p>
  
  <p>What changes do I need to make in this code to get the desired results?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;cstdio&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  int main() {
      int n,q;
      cin&gt;&gt;n&gt;&gt;q;
  
      vector&lt;int&gt; var[n];
      for(int i=0;i&lt;n;i++)
      {
          int size;
          cin&gt;&gt;size;
          for(int j=0;j&lt;size;j++)
          {
              int elm;
              cin&gt;&gt;elm;
              var[n].insert(var[n].begin(),elm);
              var[n].begin()++;
          }
      }
  
      for(int i=0;i&lt;q;i++)
      {
          int vindex,index;
          cin&gt;&gt;vindex&gt;&gt;index;
          cout&lt;&lt;var[vindex][index]&lt;&lt;"\n";
      }  
      return 0;
  }
  </code></pre>