You are given a 0-indexed integer array nums and an integer k.

You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.

You want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.

Return the maximum score you can get.

new solution update 2022.07.09

1 2 3 4 5 6 7 8 9 10 11 12 13 14

classSolution { public: intmaxResult(vector<int>& A, int k){ priority_queue<pair<int,int>> pq; pq.push({A[0],0}); int res = A[0]; for(int i = 1; i < A.size(); i++) { while(!pq.empty() and pq.top().second + k < i) pq.pop(); res = pq.top().first + A[i]; pq.push({res, i}); } return res; } };