title: Getting segmentaition fault with subset dp problem
body: <p>Given a set of numbers, check whether it can be partitioned into two subsets such that the sum of elements in both subsets is same or not
  I am getting segmentation fault in C++(g++ 5.4) with a this problem.
  This is where i submitted my solution in C++</p>
  
  <p><a href="https://practice.geeksforgeeks.org/problems/subset-sum-problem/0" rel="nofollow noreferrer">https://practice.geeksforgeeks.org/problems/subset-sum-problem/0</a></p>
  
  <p>I am checking if the array can be divided into two parts with equal sum. So I am just checking if there exists a subset with sum equal to half the sum of the array</p>
  
  <p>I have implemented the below logic with dynamic programming</p>
  
  <p>Let dp[i][j] denote yes or no whether a subset with sum j is possible to form with elements in the range [0, i](both inclusive) where i is 0-based index. I have done nothing new with this traditional problem. But I am getting segmentation fault. The program is giving correct output for small test cases. What mistake have I made</p>
  
  <p>I haven't used any comments because I have done nothing new. Hope it is understandable.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;bits/stdc++.h&gt;
  #include&lt;cstdio&gt;
  #define ll long long int
  using namespace std;
  
  
  bool isVowel(char c){
      return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
  }
  
  bool isLower(char c){
      return 97 &lt;= c &amp;&amp; c &lt;= 122;
  }
  
  
  int main() {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      cout &lt;&lt; setprecision(10);
  
      ll t, n;
      cin &gt;&gt; t;
      while (t--) {
          cin &gt;&gt; n;
          ll a[n];
          ll sum = 0;
  
          for (ll i = 0; i &lt; n; i++) {
              cin &gt;&gt; a[i];
              sum += a[i];
          }
  
          if (sum % 2) {
              cout &lt;&lt; "NO" &lt;&lt; '\n';
              continue;
          }
  
          sum /= 2;
          ll dp[n][sum + 1];
          for (ll i = 0; i &lt; n; i++) {
              for(ll j = 0; j &lt; sum + 1; j++) {
                  dp[i][j] = 0;
              }
          }
  
          for (ll i = 0; i &lt; n; i++) {
              dp[i][a[i]] = 1;
              dp[i][0] = 1;
          }
  
  
          for (ll i = 1; i &lt; n; i++) {
              for (ll j = 1; j &lt; sum + 1; j++){
                  if (j - a[i] &gt; 0) {
                      dp[i][j] = dp[i - 1][j - a[i]];
                  }
  
                  dp[i][j] |= dp[i - 1][j];
              }
          }
  
          cout &lt;&lt; (dp[n - 1][sum] ? "YES" : "NO") &lt;&lt; '\n';
  
      }
  }
  </code></pre>