Best Java Solution || Priority Queue || Sorting
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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[] pf, int[] cp) {\n        \n        int n = pf.length;\n        int arr[][] = new int[n][2];\n        for(int i=0; i<n; i++){\n            arr[i] = new int[]{pf[i],cp[i]};\n        }\n\n        Arrays.sort(arr,(a,b)->(a[1]-b[1]));\n\n        PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());\n\n        int i=0;\n\n        while(k>0){\n            while(i<n && w>=arr[i][1]){\n                pq.add(arr[i][0]);\n                i++;\n            }\n            if(pq.size()!=0){\n                w = w+pq.remove();\n            }\n            k--;\n        }\n        return w;\n    }\n}\n```
['Java']