Heap sort, each time put all profits less than or equal to current capital into the heap, take the maximum, then update capital, repeat the above operations until k times have been performed or there are no projects to invest in.
using std::vector; using std::unordered_map; using std::pair; using std::priority_queue;
classSolution { public: intfindMaximizedCapital(int k, int w, vector<int> &profits, vector<int> &capital) { int n = profits.size(); int i, selected = 0;
vector<pair<int, int> > prof2cap;
for (i = 0; i < n; i++) { prof2cap.push_back({ profits[i], capital[i] }); }