# Why am i getting seg fault?

This is my solution for the partition problem and I am unable to figure out for which case it is giving segfault. Need help. This is the problem :

`````` #include<bits/stdc++.h>
using namespace std;
inline bool sub(int arr[], int n, int sum){
int dp[n+1][sum+1];
for(int i = 0 ; i <= n ; i++)
dp[i][0] = 1;
for(int i = 1 ; i <= sum ; i++)
dp[0][i] = 0;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= sum ; j++){
if(j < arr[i-1])
dp[i][j] = dp[i-1][j];
else
dp[i][j] = dp[i-1][j] + dp[i-1][j - arr[i-1]];
}
}
if(dp[n][sum] != 0)
return true;
return false;
}
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int sum = 0, arr[n];
for(int i = 0 ; i < n ; i++){
cin >> arr[i];
sum += arr[i];
}
if(sum % 2 != 0 || (n == 1 && sum != 0))
cout << "NO" << endl;
else{
if(n == 0 || sum == 0 || sub(arr, n, sum/2))
cout << "YES";
else
cout << "NO";
cout << endl;
}
}
return 0;
}
``````

Code seems to work fine on my system. Can you share the testcase?

I found out the problem. I converted `int dp[n+1][sum+1]` to `bool dp[n+1][sum+1]`. There was memory overflow as I was using `int`. `Bool` saved a lot of space and it worked out fine. Thanks for looking into it.