queue and an array dp with the same length as nums.i over the indices of nums:
i minus the front of queue is greater than k, remove from the front of queue.dp[i] to dp[queue.front()] + nums[i]. If queue is empty, use 0 instead of dp[queue.front()].dp[queue.back()] is less than dp[i], pop from the back of queue.dp[i] > 0, push i to the back of queue.dp.