Python solution using DP
Code\n\nclass Solution:\n    def maximizeWin(self, A: List[int], k: int) -> int:\n        dp = [0] * (len(A) + 1)\n        res = j = 0\n        for i, a in enum
# Code\n```\nclass Solution:\n    def maximizeWin(self, A: List[int], k: int) -> int:\n        dp = [0] * (len(A) + 1)\n        res = j = 0\n        for i, a in enumerate(A):\n            while A[j] < A[i] - k: j += 1\n            res = max(res, i - j + 1 + dp[j])\n            dp[i + 1] = max(dp[i], i - j + 1)\n        return res\n```
['Python3']