2
public int constrainedSubsetSum(int[] nums, int k) {6
Queue<Integer> queue = new PriorityQueue<>((a, b) -> dp[b] - dp[a]); // Declaring Max heap8
Arrays.fill(dp, Integer.MIN_VALUE);12
for (int j = 1; j < n; j++) {13
int i = Math.max(j - k, 0); // get the furthest index possible14
while (!queue.isEmpty() && queue.peek() < i)15
queue.poll(); // find the global max in the specified range for that particular j index16
int idx = queue.peek();17
dp[j] = Math.max(dp[idx] + nums[j], nums[j]);18
res = Math.max(res, dp[j]);