PriorityQueue Optimize Solution
Complexity\n- Time complexity:O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(N*2)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N*2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n        int [][] proj = new int[profits.length][2];\n        for(int i=0; i<profits.length; i++){\n            proj[i][0]=capital[i];\n            proj[i][1]=profits[i];\n        }\n        Arrays.sort(proj, (a, b)->Integer.compare(a[0], b[0]));\n\n        int i=0;\n        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n        while(k-->0){\n            while(i<profits.length && proj[i][0]<=w){\n                pq.offer(proj[i][1]);\n                i++;\n            }\n\n            if(pq.isEmpty()){\n                break;\n            }\n            w+=pq.poll();\n        }\n\n        return w;\n    }\n}\n```
['Array', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Java']