Error on 4th Test case

I’ve written the code for ‘Blocked Billboard ii’ but i’ve been stuck on the fourth test case failure for a long while. I know it’s a simple problem but somehow, the other test cases work and I’m not able to wrap my head around it.

Here’s the link to the problem:
Here’s my code:
Here’s the link to the test cases along with the usaco solution:


Have you tried downloading the test data?