WESTAND Need help (DP hard)



I am trying to solve WESTAND problem from DEC-17 long Challenge. There is no editorial for this problem and the solutions submitted are not helping either. Can someone share their approach or share some idea on how to solve this problem?

I am referring to these solutions:

  1. https://www.codechef.com/viewsolution/16536356

  2. https://www.codechef.com/viewsolution/16546353

  3. https://www.codechef.com/viewsolution/16546228


I have not gone through the question yet, but this might help: link


i have read it, its still not very clear