How to solve this grid problem

It is very much similar to this CSES problem set in dynamic programming