JS priority queue +explanation
Performance\nRuntime 447ms Beats 66.27% Memory 101.1MB Beats 10.84%\n\n### Intuition\nWe need to find the k projects which yield the greatest overall profit.  S
### Performance\nRuntime 447ms Beats 66.27% Memory 101.1MB Beats 10.84%\n\n### Intuition\nWe need to find the `k` projects which yield the greatest overall profit.  Since *the operating capital never goes down* we don\'t have a house robbber situation where choosing one project has an opportunity cost which would keep us from choosing another more lucrative combination of projects later.  We only need to choose the most profitable project we can afford to invest in each time.\n\n### Approach\n- Start with a list of project sorted by capital cost ascending and a priority queue.\n- Before choosing the next project, enqueue jobs until the the capital cost exceeds your operating capital `w`.\n- dequeue the most profitable project and add it to the operating capital.\n- Repeat `k` times or until all the projects are run.\n\n### Complexity\n- Time complexity: O(nlogn) or O(klogn)\n\n- Space complexity: O(n)\n\n### Code\n```\n/**\n * @param {number} k\n * @param {number} w\n * @param {number[]} profits\n * @param {number[]} capital\n * @return {number}\n */\nvar findMaximizedCapital = function(k, w, profits, capital) \n{\n    /* Sort the projects by capital cost. */\n    let projects = [];\n    for(let i=0; i<profits.length; i++)\n        projects.push([profits[i],capital[i]]);\n    projects.sort((a,b)=>a[1]-b[1]);\n\n    /* Run the projects. */\n    let pq = new MaxPriorityQueue(), pp = 0;\n    while(k > 0)\n    {\n        /* Add all the projects fundable with the current operating capital. */\n        while(pp < projects.length && projects[pp][1] <= w)\n        {\n            pq.enqueue(pp,projects[pp][0]);\n            pp++;\n        }\n\n        if(pq.size() === 0)\n            break;\n\n        /* Choose the most profitable available project. */\n        let el = pq.dequeue();\n        w += el.priority;\n        k--;\n    }\n\n    return w;\n};\n```
['JavaScript']