Recursive || 2D dp
When skipping, we skip all the occurances of current element.\nWhen picking, we pick till the indx where the element is greater than current element + k.\n\n# C
When skipping, we skip all the occurances of current element.\nWhen picking, we pick till the indx where the element is greater than current element + k.\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(vector<int>& prizePositions, vector<vector<int>>& dp, int k, int indx, int segments) {\n        if(indx == prizePositions.size())\n        return 0;\n        if(segments == 0)\n        return 0;\n\n        if(dp[indx][segments] != -1)\n        return dp[indx][segments]; \n\n        int skipToIndex = lower_bound(prizePositions.begin(), prizePositions.end(), prizePositions[indx]+1) - prizePositions.begin();\n        int skipped = solve(prizePositions, dp, k, skipToIndex, segments);\n\n        int pickTillIndex = lower_bound(prizePositions.begin(), prizePositions.end(), prizePositions[indx]+k+1) - prizePositions.begin();\n        int picked = pickTillIndex - indx + solve(prizePositions, dp, k, pickTillIndex, segments-1);\n\n        return dp[indx][segments] = max(skipped, picked);\n    }\n    int maximizeWin(vector<int>& prizePositions, int k) {\n        vector<vector<int>> dp(prizePositions.size() + 1, vector<int> (3, -1));\n        return solve(prizePositions, dp, k, 0, 2);\n    }\n};\n```
['Recursion', 'C++']