-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.h
37 lines (36 loc) · 995 Bytes
/
solution.h
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
29
30
31
32
33
34
35
36
37
/*
Code generated by https://github.com/goodstudyqaq/leetcode-local-tester
*/
#if __has_include("../utils/cpp/help.hpp")
#include "../utils/cpp/help.hpp"
#elif __has_include("../../utils/cpp/help.hpp")
#include "../../utils/cpp/help.hpp"
#else
#define debug(...) 42
#endif
class Solution {
public:
int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {
int n = capital.size();
vector<int>f(n);
iota(f.begin(), f.end(), 0);
sort(f.begin(), f.end(), [&](int x, int y) {
return capital[x] < capital[y];
});
int now = 0;
multiset<int> S;
while (k--) {
while (now < n && capital[f[now]] <= w) {
S.insert(profits[f[now]]);
now++;
}
if (S.size() == 0) {
break;
}
auto it = S.rbegin();
w += *it;
S.erase(prev(S.end()));
}
return w;
}
};