Joey and the journey to become a film star

0

0 votes
Easy-Medium
Problem

Joey and the journey to become a film star

enter image description here

We all know how much Joey loves acting. Now his dream to become an actor is really close. All that is left is to pass the forest of DEATH. Forest of death is a place that takes away your life energy and ultimately you die. This forest also has many potions to restore your energy. The only way to cross the forest is by collecting maximum potions. Joey can start his journey from any location at head of forest (1st row) and has to reach the tail of forest (last row). Joey wants to know the maximum amount of potion that he can get when the journey is finished. from [i,j] , he can go to [i+1,k] iff abs(j-k) is a prime.

Input:

The first line has N ans M (Rows and columns)

Then N lines follows each having M values denoting amount of potion at that location.

Output:

Maximum amount of potion at the end.

Constraints:

1N,M800

1F[i][j]105

Problem Setter - Satyarth

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Editor Image

?