title: Segmentation Fault Error when assigning values to array
body: <p>I'm currently doing a basic simulation problem in <a href="http://www.usaco.org/index.php?page=viewproblem2&amp;cpid=568" rel="nofollow noreferrer">USACO</a>.
  I'm pretty sure I've done the algorithm for this problem correctly, however, when I try to assign values to array, I get the error: <code>run: line 1:     3 Segmentation fault      (core dumped) LD_LIBRARY_PATH=/usr/local/gcc-9.2.0/lib64 ./a.out</code>.
  This is my code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include&lt;string&gt;
  #include &lt;cstdio&gt;
  #include &lt;cstdlib&gt;
  #include &lt;algorithm&gt;
  #include&lt;vector&gt;
  #include &lt;cmath&gt;
  #include &lt;array&gt;
  using namespace std;
  void setIO(string s) { // the argument is the filename without the extension
      freopen((s+&quot;.in&quot;).c_str(),&quot;r&quot;,stdin);
      freopen((s+&quot;.out&quot;).c_str(),&quot;w&quot;,stdout);
  }
  int main() {
      // setIO(&quot;speeding&quot;);
      string new_signal = &quot;&quot;;
      int m, n; cin &gt;&gt; m &gt;&gt; n;
      int arr1[n+m] = {0};
      int arr2[n+m] = {0};
      for(int i = 0; i &lt; n+m; i++) {
          int a, b; cin &gt;&gt; a &gt;&gt; b;
          arr1[i] = a;
          arr2[i] = b;
          // cout &lt;&lt; n+m;
      }
      
      int road_limits[100] = {0};
      int counter = 0;
      for(int i = 0; i &lt; n; i++) {
          for(int j = 0; j &lt; arr1[i]; j++) {
              road_limits[counter] = arr2[i];
              counter++;
          }
      }
      counter = 0;
      int max_over_limit = -200;
      for(int i = n; n &lt; n+m; n++) {
          for(int j = 0; j &lt; arr1[i]; j++) {
              if((arr2[i] - road_limits[counter]) &gt; max_over_limit){
                  max_over_limit = (arr2[i] - road_limits[counter]);
              }
              counter++;
          }
      }
      
      cout &lt;&lt; max_over_limit;
      return 0;
  }
  </code></pre>
  <p>After debugging with print statements, it appears that my code gets the Segmentation Fault error somewhere in the first for loop where I assign the values of arr1 and arr2(no <code>cout</code> statements run past that point). I'm not why this would be the case though. I'm relatively new to using C++, so is there something that I'm misunderstanding that causes this error?</p>