Why do I get Run Time Error(SIGSEGV)?

I know it is usually due to invalid memory reference and the use of too much memory, but according to the problem description, the matrix shouldn’t be too large.
Problem link: https://www.codechef.com/problems/MAXCOMP
My solution: https://www.codechef.com/viewsolution/61784871

I think the line no 43 can lead to negative index which can in turn give SIGSEV.

If you are sure that in this line ( j - diff ) is always positive then please confirm I will check once again.

            dp[i][j]=std::max(dp[i-1][j],dp[i-1][j-diff]+comp);
1 Like

(j-diff) in that line is basically the variable start, it shouldn’t give a negative index. Now that I think of it, I should probably put just start.

1 Like

Yes I noticed now that it’s just start I missed the if conditions

1 Like