Topcoder SRM 695 Div 2 level 2

Hey guys. I was hoping somebody could explain how to proceed ahead with this question.

I can definitely think of a brute force solution to this problem, but given the time constraints, brute force wouldn't work. Could someone please explain the solution approach?

Link to Problem

Thanks

Comments (0)