Run error is coming in this code

#include
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,S;
cin>>N>>S;

int wt[N];
int val[N];
for(int i=0;i<N;i++){
	int w;
	cin>>w;
	wt[i]=w;
}
for(int i=0;i<N;i++){
	int v;
	cin>>v;
	val[i]=v;
}
int dp[N+1][S+1];
for(int i=0;i<=N;i++){
	for(int j=0;j<=S;j++){
		if(i==0 or j==0){
			dp[i][j]=0;
		}
		else if(wt[i-1]<=j){
			dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
		}
		else{
			dp[i][j]=dp[i-1][j];
		}
	}
}
return dp[N][S];

}

Hello @mansi25 I suggest you to dry run your code.it must be going out of bound in indexing or check the constraints.
If you still are not able to find the error please write here.
We will discuss.
Happy Learning!!

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.