MAXPR - getting WA

I am getting WA in the following code. I tried most of the possible test cases and it is giving the correct answers but getting WA still. Can someone help me, what I am missing ?

Thanks in advance :slight_smile:

link to problem : http://www.codechef.com/problems/MAXPR
link to code : http://www.codechef.com/viewsolution/4149667

At each iteration you are doing,
cnt = cnt + dp[i];
Ideally, you should be taking modulus at each step.
So, try doing “%MAX” at each iteration.

It is taking modulus at each step… see the next lines
" if (cnt >= MAX)
cnt -= MAX;
}"
it will automatically take the modulus!