Can you find the error. Working absolutely fine for the stock 3 problem. here runtime error


#1

int Solution::solve(vector &A, int B) {
if(A.size()==0){
return 0;
}
long n = A.size();
long temp[B+1][A.size()];

for(long i=0;i<n;i++){
    temp[0][i] = 0;
}
for(long i=0;i<=B;i++){
    temp[i][0]=0;
}    

for(long i = 1;i<=B;i++){
    long maxi = temp[i-1][0]-A[0];
    for(long j=1; j<n;j++){
        
        temp[i][j] = max(temp[i][j-1], A[j] + maxi);
        maxi=max(maxi, temp[i-1][j]-A[j]);
    }
}
return (int)temp[B][n-1];

}