DP+Binary Search||C++||Recursive Solution
\nclass Solution {\npublic:\n    vector<vector<int>>dp;\n    int fn(int ind,vector<int>&arr,int segment,int k) \n    {\n        if(segment==0)\n            retu
```\nclass Solution {\npublic:\n    vector<vector<int>>dp;\n    int fn(int ind,vector<int>&arr,int segment,int k) \n    {\n        if(segment==0)\n            return 0;\n        if(ind>=arr.size())\n            return 0;\n        if(dp[ind][segment]!=-1)\n            return dp[ind][segment];\n        \n        int non_pick=fn(ind+1,arr,segment,k); \n        int target=lower_bound(arr.begin(),arr.end(),arr[ind]+k+1)-arr.begin();\n        int pick=target-ind; \n        \n        pick+=fn(target,arr,segment-1,k);\n        \n        return dp[ind][segment]= max(non_pick,pick);\n        \n        \n    }\n        \n    int maximizeWin(vector<int>& arr, int k) {\n        int n=arr.size();\n        dp.resize(n,vector<int>(3,-1));\n        \n        return fn(0,arr,2,k);\n        \n        \n    }\n};\n```
['Binary Search', 'Dynamic Programming', 'Recursion', 'C']