Collecting_apples

How to solve https://www.hackerearth.com/practice/algorithms/dynamic-programming/2-dimensional/practice-problems/algorithm/collecting-apples-69/ question on HackerEarth?

//