Only 1 test case is passing.why are the rest run time error

#include
#include<bits/stdc++.h>
using namespace std;
class point
{
public:
int weight;
int profit;
};
bool comp(point &a,point &b)
{
return a.weight<b.weight;
}
int main() {
int n,w;
cin>>n>>w;
point arr[n+1];
arr[0].weight=0;
arr[0].profit=0;
for(int i=1;i<n+1;i++)
{
cin>>arr[i].weight;
}
for(int i=1;i<n+1;i++)
{
cin>>arr[i].profit;
}
sort(arr,arr+n+1,comp);
int dp[n+1][w+1];
memset(dp,0,sizeof(dp));
for(int i=0;i<n+1;i++)
{
dp[0][i]=0;
}
for(int i=0;i<w+1;i++)
{
dp[i][0]=0;
}
for(int i=1;i<n+1;i++)
{
for(int j=1;j<w+1;j++)
{
if(j<arr[i].weight)
dp[i][j]=dp[i-1][j];
else
dp[i][j]=max((arr[i].profit)+(dp[i-1][j-(arr[i].weight)]),(dp[i-1][j]));
}
}
cout<<dp[n][w]<<endl;
}

@neha_153,
Please provide Coding Blocks IDE link of your code.

what is coding blocks ide?

@neha_153,
Try clicking on -> Coding Blocks IDE <-
There Paste your code. Hit Save. Then copy the URL and paste here.

@neha_153,
Updated Code: here

  • Declare array with constant size.
  • Don’t use memset.
  • You don’t need sort function.

@neha_153,
Please make sure you share a properly indented code. No one wants to look into a messy code.