import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param nums int整型一维数组
     * @return int整型
     */
    public int maxJumpGrade (int[] nums) {
        // write code here
        // 解题思路:采用贪心算法
        // 从最末尾节点开始,依次往前推,求到每个节点的最大分数 
        if (nums == null || nums.length == 0) {
            return -1;
        }

        int length = nums.length;
        int score = nums[length - 1];
        int end = length - 1;


        for (int i = length - 2; i >= 0; i--) {
            if (i + nums[i] >= end ) {
                score += nums[i];
                end = i;
            }
        }

        return end == 0 ? score : -1;
    }
}