Only one test case passed

#include<bits/stdc++.h>
using namespace std;

bool ans(int n,int sum,vector&arr){
if(n==0){
return 0;
}
bool dp[n+1][sum+1];
for(int i=0;i<=n;i++){
dp[i][0] = true;
}

for(int j=1;j<=sum;j++){
dp[0][j] = false;
}

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];
}

	  if(j>=arr[i-1]){
		  dp[i][j] = dp[i-1][j] || dp[i-1][j-arr[i-1]];
	  }

  }

}

return dp[n][sum];

}
int main() {
int n;
cin>>n;
int sum;
cin>>sum;
vectorarr;
for(int i=0;i<n;i++){
int x;
arr.push_back(x);
}

if(ans(n,sum,arr)==true){
	cout << "Yes" << endl;
}else{
	cout<< "No" << endl;
}

}

Hello Mohit,

remove this if statement ,i.e assign dp[i][j]=dp[i-1][j] without checking j < arr[i-1]

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.