1
# Runtime: 1386 ms (Top 69.5%) | Memory: 30.16 MB (Top 58.7%)5
def constrainedSubsetSum(self, nums: List[int], k: int) -> int:7
for i, num in enumerate(nums):10
deque and deque[0] < i - k11
): # delete that didn't end with a number in A[i-k:i]14
if deque: # compute the max sum we can get at index i15
nums[i] = nums[deque[0]] + num17
while deque and nums[deque[-1]] < nums[i]:18
# delet all the sequence that smaller than current sum, becaus there will never be19
# considers ==> smaller than current sequence, and end before current sequence22
if nums[i] > 0: # if nums[i] < 0, it can't be a useful prefix sum