Sort index by capital. Then use heap. C++.
First create a vector of index, sort by capital.\nThen go through this index vector, put profits of all qualified projects into a queue. Pick the highest profit
First create a vector of index, sort by capital.\nThen go through this index vector, put profits of all qualified projects into a queue. Pick the highest profit.\nWe may not be able to finish k projects. Quit if we cannot pay the minimum capital.\n```\n\tint findMaximizedCapital(int k, int W, vector<int>& Profits, vector<int>& Capital) {\n\t\tpriority_queue<int> heap;\n\t\tint n = 0;\n\t\tvector<int> idx(Profits.size());\n\t\tfor_each(idx.begin(), idx.end(), [&n](int& i) {i = n++; });\n\t\tsort(idx.begin(), idx.end(), [&Capital](int i, int j) {return Capital[i] < Capital[j]; });\n\t\tint i = 0;\n\t\twhile (k > 0) {\n\t\t\twhile (i < idx.size() && W >= Capital[idx[i]]) {\n\t\t\t\theap.push(Profits[idx[i++]]);\n\t\t\t}\n\t\t\tif (heap.empty()) {\n\t\t\t\treturn W;\n\t\t\t}\n\t\t\tW += heap.top();\n\t\t\theap.pop();\n\t\t\tk--;\n\t\t}\n\t\treturn W;\n\t}\n```
[]