I was trying to solve this problem on Codechef, " https://www.codechef.com/ICOP1904/problems/GRP ". I understand that I have to use DP to solve it and also that I have to maintain two states, but I am unable to figure out how to proceed to solve it. I even looked at some submissions but I am still not sure if I got it completely. Can someone please explain me how to solve the problem. Thanks in advance..
I was trying out this problem and i am getting WA.I have thought about the dp states and tried some test cases too and i cant find my mistake.If anyone could point out some mistake in my code it would be of great help!! Link to my solution https://ideone.com/lcUUTo .Kindly open the code in your local text editor so that the comments would be readable.Thanks in advance!!
Try this input for which output should be -1
thanks!! i thought -1 condition would never occur so i just printed ans value
https://discuss.codechef.com/questions/144196/brief-editorials-ico-preparatory-mega-contest-icop1904 Read this!! Happy coding
Thank you. I got it now.