Python3 Dynamic programming
Approach\n- Need to choose at most two segment, the dfs function should go through all index or run out of two segments.\n- There are two states in each index, 
# Approach\n- Need to choose at most two segment, the dfs function should go through all index or run out of two segments.\n- There are two states in each index, pick or not pick\n- If pick the idx, skip the value less or equal than the value plus k. \n    ex: `prize[idx] = 1 and k = 2`\n    It can cover from value 1 to 3, so find the next first index larger than 3, using binary search to find next index\n- If skip the index, skip all the index with the same value.\n    ex: `prize = [1,1,1,1,2,2,2,3,3]`\n    If skip index 0, should also skip other index with the same value `1`, it won\'t bring larget answer, using binary search to find the next first index of value larger than 1d\n\n# Complexity\n- Time complexity:\nO( n * log(n) *2)\n\n- Space complexity:\nO( n )\n\n# Code\n```\nclass Solution:\n    def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n        @cache\n        def dfs(idx, n):\n            if idx==len(prizePositions) or n==0:\n                return 0\n            left = bisect.bisect_right(prizePositions, prizePositions[idx]+k)\n            i = bisect.bisect_right(prizePositions, prizePositions[idx])\n            a = dfs(left, n-1)+left-idx\n            b = dfs(i, n)\n            return max(a,b)\n        return dfs(0, 2)\n```\n\nIterator\n```\nclass Solution:\n    def maximizeWin(self, prizePositions: List[int], k: int) -> int:\n        dp = [0 for _ in range(len(prizePositions)+1)]\n        ans = 0\n        for i in range(len(prizePositions)):\n            if i>0:\n                dp[i] = max(dp[i], dp[i-1])\n            left = bisect.bisect_right(prizePositions, prizePositions[i]+k)\n            dp[left] = max(dp[left], left-i)\n            ans = max(ans, dp[i]+left-i)\n        return ans\n```
['Dynamic Programming', 'Python3']