ash_vs_ash's blog

By ash_vs_ash, history, 6 years ago, In English

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..

Tags #dp
  • Vote: I like it
  • -18
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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!!

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Try this input for which output should be -1

    1
    5
    2 2
    0 1 0 1 0
    10 5 11 4 1
    
    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      thanks!! i thought -1 condition would never occur so i just printed ans value

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it