forked from lzl124631x/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths1.cpp
More file actions
28 lines (28 loc) · 883 Bytes
/
Copy paths1.cpp
File metadata and controls
28 lines (28 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
struct CapCmp {
bool operator()(pair<int, int> &a, pair<int, int> &b) {
return a.first > b.first;
}
};
struct ProCmp {
bool operator()(pair<int, int> &a, pair<int, int> &b) {
return a.second < b.second;
}
};
class Solution {
public:
int findMaximizedCapital(int k, int W, vector<int>& Profits, vector<int>& Capital) {
priority_queue<pair<int, int>, vector<pair<int, int>>, CapCmp> cap;
priority_queue<pair<int, int>, vector<pair<int, int>>, ProCmp> pro;
for (int i = 0; i < Profits.size(); ++i) cap.push({ Capital[i], Profits[i] });
while (k--) {
while (cap.size() && cap.top().first <= W) {
pro.push(cap.top());
cap.pop();
}
if (pro.empty()) return W;
W += pro.top().second;
pro.pop();
}
return W;
}
};