Here is the link to the problem https://www.codechef.com/INOIPRAC/problems/TWOPATHS.

I am not able to get the logic behind the problem. I know this question has been asked before but not much have been explained there.

Can anyone explain me a detailed solution for this problem. Any help will be appreciated:)

I am Two Paths, the true heir of Salazar Slytherin. I felt that it would not be safe to open the Discuss Forum of CodeChef while I was at school, so I left behind a diary of my 16-year old self, hoping that one day, I would be able to finish Salazar Slytherinâ€™s noble work. And havenâ€™t I told you? - killing mudbloods hasnâ€™t been my target for a while. My new target, for the past few months, has been you. How is that you escaped the curse of one of the greatest wizards of all time? How is it that you escaped with nothing but a scar while Lord Voldemortâ€™s powers were destroyed?

Coming to the problem, there are two hints I can give you :

Use prefix sums and Dynamic programming. There is a detailed editorial in this Forum. Find it by yourself.

I saw the editorial prior to asking this question and I couldnâ€™t understand it as the author only briefly described the solution(according to me).

Not a lot many potterheads in the community

Youâ€™d do better by asking beneath the editorial itself.

I would have but the editorial itself was 3 years old. So I thought even if Iâ€™d ask my question it would most probably go unanswered as the editorial was inactive now.

Untrue, I wrote the editorial and I regularly respond to non trivial help requests (no, I wonâ€™t debug your code)

Iâ€™m sorry but I never came across your editorial. The link which Iâ€™m talking about is this oneâ€¦https://discuss.codechef.com/t/inoi-2018-discussion/17777/8.

Particulary this comment in the editorial by ista2000,

For second one, The observation was that, we can take one path and calculate the total sum without a second path using dp[i][j][k] = min/max(dp[i-1][j][k], dp[i-1][j-1][k-1])+prefix_sum[i][j]. We calculate this two times, once for min and once for max and then we can use the prefix sum intuition to subtract min-dp from max-dp. Itâ€™s not clear enough here, but you might get an essence.

Other than this link and this comment, I havenâ€™t found any other thing.

Could you please provide me with the link of the editorial written by you.(I tried searching but am not able to find it).

Also, try searching by the problem code rather than the problem name.

Thank you so much man. Sorry if any trouble caused.

Will do. If I had known that it would have saved you the trouble.