Minimum money Needed giving error

#include<bits/stdc++.h>
using namespace std;
int dp[1000][1000];
int helper(int arr[],int n,int W){

for(int i=0;i<=W;i++){
	dp[0][i]=INT_MAX;
}
for(int i=1;i<=n;i++){
	for(int w=1;w<=W;w++){
		if(w<arr[i-1]){
			dp[i][w]=dp[i-1][w];
		}
		else{
			dp[i][w]=min(arr[i-1]+dp[i-1][w-i],dp[i-1][w]);
		}
		
		
	}
	
	
}
return dp[n][W];

}
int main() {
int n,k;
cin>>n>>k;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
memset(dp,0,sizeof(dp));
cout<<helper(arr,n,k);

return 0;

}

hi @kumawatnitesh093 what about -1 case
check this
5 10
-1 33 -1 176 -1 46 -1 120 -1 300
ans is 112
refer this