Memory Limit Exceeded with array


#1

My solution is getting Memory Limit Exceeded when I use array for dp and ind variables in my code below but gets accepted if I use vector for both. Can anyone explain why this is happening?

    vector<int> Solution::solve(int A, vector<int> &B) {
            int n=B.size();

            int dp[A+1]={0};    // This part is getting MLE
            int ind[A+1];          // This part is getting MLE

            //vector<int>dp(A+1,0),ind(A+1);    // If I uncomment here and use this vector instead of above arrays, my solution gets accepted.

            for(int i=0;i<=A;i++)
            {
                for(int j=0;j<n;j++)
                {
                    if(i>=B[j])
                    {
                        if(dp[i-B[j]]+1 > dp[i])
                        {
                            dp[i]=dp[i-B[j]]+1;
                            ind[i]=j;
                        }
                    }
                }
            }
            
            vector<int>v;
            int x=A;
            while(x>0 && x>=B[ind[x]])
            {
                v.push_back(ind[x]);
                x-=B[ind[x]];
            }
            return v;
        }

Thanks.