Use two points cleverly
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def maximizeWin(self, p: List[int], k: int) -> int:\n        i,n = 0,len(p)\n        if p[-1] - p[0] <= k:\n            return n\n        pre = [0]\n        i = 0\n        for j in range(1,n):\n            if p[j] - p[i] > k:\n                i += 1\n            else:\n                pre.append(j)\n        sub = [n-1]\n        j = n-1\n        for i in range(n-2,-1,-1):\n            if p[j] - p[i] > k:\n                j -= 1\n            else:\n                sub.append(i)\n        \n        sub = sub[::-1]\n        i,j = 0,0\n        ans = -len(sub)\n        while i < len(pre) and j < len(sub):\n            if pre[i] >= sub[j]:\n                j += 1\n            else:\n                ans = max(i-j,ans)\n                i += 1\n        return ans  + len(sub) + 1\n\n\n\n                \n            \n\n            \n\n\n\n```
['Python3']