Portals II
You are standing at the first index of an array of length . At index , you can either take a step forward to , or if there is a portal ( portals) such that , you can teleport to any index in . The score of a path is defined as the maximum sum of values of the indicies you visit. What is the maximum score with which you can get to index , starting from the start of the array?
Sample Input
5 1
1 2 -100 4 5
1 2 3
Sample Output
12
Constraints
Comments