Best solution | very optimized | with vid explanation to make concept super easy
detailed problem statement explanation + approach + optimization\nwatch in 2x to save your time\n\nhttps://youtu.be/yGket_WqTqA\n\n# Intuition\n Describe your f
detailed problem statement explanation + approach + optimization\nwatch in 2x to save your time\n\nhttps://youtu.be/yGket_WqTqA\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe approach involves sorting the projects based on their capital requirements and using a max-heap (priority queue) to efficiently manage and retrieve the highest profits of available projects that can be started with the current capital.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInitialization:\n- Create a vector store to hold pairs of (capital, profit) for each project.\n- Use a priority queue pq to keep track of the profits of projects that can be started.\n- Store the initial capital in totalCapital.\n\nStoring and Sorting Projects:\n- All projects are stored in the store vector as pairs of (capital, profit).\n- The store vector is sorted based on the capital requirements to facilitate easy access to projects that can be started with the current capital.\n\nProcessing Projects:\n- Iterate up to k times (the maximum number of projects that can be completed).\n- Move all projects whose capital requirement is less than or equal to the current total capital into the priority queue pq.\n- We use an index (i) to track the current position in the sorted store vector to avoid re-sorting or re-scanning the entire list.\n- If the pq is empty (no projects can be started), break out of the loop.\n\nSelect the project with the maximum profit from the pq and add its profit to the total capital.\nThis corrected approach ensures that projects are handled correctly and efficiently.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N log N + N log K)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        \n        vector<pair<int,int>> store;\n        int total_capital = w;\n\n        int n = profits.size();\n\n        for(int i=0;i<n;i++){\n\n            store.push_back({capital[i],profits[i]});\n            \n        }\n\n        sort(store.begin(), store.end());\n\n        priority_queue<int> pq;\n\n        int i = 0;\n\n        while(k--){\n\n            for(;i<n;i++){\n\n                int profit = store[i].second;\n                int capital = store[i].first;\n\n                if(capital > total_capital) break;\n\n                pq.push(profit);\n                \n            }\n\n            if(pq.empty()){\n\n                break;\n                \n            }\n\n            int ideal_profit = pq.top();\n            pq.pop();\n\n            total_capital += ideal_profit;\n            \n        }\n\n        return total_capital;\n        \n    }\n};\n```
['C++']