Untitled
unknown
plain_text
2 years ago
691 B
5
Indexable
class Solution {
public:
int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& cap) {
priority_queue<int> pq;
vector<pair<int, int>> projects;
for (int i = 0; i < cap.size(); ++i) {
projects.push_back({cap[i], profits[i]});
}
sort(projects.begin(), projects.end());
int i = 0;
while (k--) {
while (i < projects.size() && projects[i].first <= w) {
pq.push(projects[i].second);
++i;
}
if (!pq.empty()) {
w += pq.top();
pq.pop();
}
}
return w;
}
};Editor is loading...
Leave a Comment