Given an array of *N* integers (elements are either positive or -1), and another integer *M*.  

For each *1 <= i <= N*, we can jump to *i + 1, i + 2, .. i + M* indexes of the array. Starting from index 1 is there a linear *O(N)* algorithm that can find out the minimum cost as well as the path to reach Nth index. Where cost is the sum of all elements in the path from 1 to N. I have a dynamic programming solution of complexity of *O(N\*M)*.  

Note: If A[i] is -1, then it means that we can't land on ith index.