C++
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:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& prizePositions, int k) {\n        //It is meaningless to let the two interval to overlap\n        int l = prizePositions.size();\n        if(prizePositions[l-1] - prizePositions[0] <= 2*k+1) return l;\n        //now we can assume they don\'t overlap. \n        //so we search the interval through [m,m+k] to [M-k,M]\n        //and use Mi,Mj to mark the first interval that we can get most prizes from prizePisitions[Mi] to prizePositions[Mj-1], where prizePositions[Mj-1]+k <= curi, and curi to curj is the second interval\n        //if we find more prizes in the second interval, we will renew the Mi and Mj to the new ones as soon as they don\'t overlap\n        int Mi=0,Mj=0;//mark our first interval\n        queue<pair<int, int>> previousIntervals;//stores possible larger intervals for our first interval\n        int ans = 0;\n        int curi=0,curj=Mj;\n        for(;curi<l;curi++)\n        {\n            //find interval\n            while(curj < l && prizePositions[curj] - prizePositions[curi] <= k)\n            {\n                curj++;\n            }\n            //If there are no overlap we can replace the old first interval with the new first interval.\n            while(!previousIntervals.empty() && previousIntervals.front().second <= curi)\n            {\n                if(previousIntervals.front().second - previousIntervals.front().first > Mj - Mi)\n                {\n                    Mj = previousIntervals.front().second;\n                    Mi = previousIntervals.front().first;\n                }\n                previousIntervals.pop();\n            }\n            if(curj-curi > Mj - Mi)//If we find a larger interval\n            {\n                previousIntervals.push(make_pair(curi,curj));\n            }\n            if(curj - curi + Mj - Mi > ans) ans = curj-curi+Mj-Mi;\n        }\n        return ans;\n    }\n};\n```
['C++']