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] }); }
i = 0; while (k--) { // 把所有capital小于w的加入堆 while (i < n && prof2cap[i].second <= w) { profit_heap.push(prof2cap[i++].first); } if (profit_heap.empty()) { break; }
w += profit_heap.top(); profit_heap.pop(); } return w; } };