Best DP + Binary search solution(c++ solution)
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    int f(int ind,int k,vector<int>&arr,int l,vector<vector<int>>&dp){\n        if(k == 0)return 0;\n        if(ind == arr.size())return 0;\n\n        if(dp[ind][k]!=-1)return dp[ind][k];\n        int nottake = f(ind+1,k,arr,l,dp);\n        int take = -1e9;\n        if(k>0){\n            int findind = lower_bound(arr.begin(),arr.end(),arr[ind]+l+1) - arr.begin();\n            take = (findind - ind) + f(findind,k-1,arr,l,dp);\n        }\n        return dp[ind][k] = max(take,nottake);\n    }\npublic:\n    int maximizeWin(vector<int>& prizePositions, int k) {\n        int n = prizePositions.size();\n        vector<vector<int>>dp(n+1,vector<int>(3,-1));//we can take at most 2 segment \n        //DP + Binary search solution(c++ solution)\n        return f(0,2,prizePositions,k,dp);\n    }\n};\n```
['C++']