Here’s the problem:

https://www.codechef.com/IOIPRAC/problems/INOI1301

Here’s my solution:

https://www.codechef.com/viewsolution/12397702

It passes all the test cases except 2, and I am having quite a hard time figuring out where I went wrong.

I understand the other solutions(namely dp on 2 arrays or using the same array in different directions) but wanted to know what was wrong with this one.

I’d appreciate if someone could point the mistake out to me, or maybe give me a test case that the code fails.

Thanks