problem: https://www.codechef.com/LTIME85A/problems/COWSHEDS
I was able to solve it when the constraints are less, how to solve it efficiently? Editorial for this question hasn't been released yet. So, it would be of great help if you could explain your approach and key concepts along with the solution.