classSolution { public: intmaxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker){ vector<int> pro { profit[0] }; vector<int> dif { difficulty[0] }; size_tsize = profit.size(); for (int i = 1, s = 0; i < size; ++i) { int d = difficulty[i]; int p = profit[i];
while (s >= 0) { if (p > pro[s]) { if (d < dif[s]) { pro.erase(pro.begin() + s); dif.erase(dif.begin() + s); --s; } else { pro.insert(pro.begin() + s + 1, p); dif.insert(dif.begin() + s + 1, d); s = dif.size() - 1; break; } } else { if (d < dif[s]) { --s; } else { s = dif.size() - 1; break; } } }
if (s == -1) { pro.insert(pro.begin(), p); dif.insert(dif.begin(), d); s = dif.size() - 1; } }
sort(worker.begin(), worker.end());
int b = 0, e = 0, lbp = 0, sum = 0; for (auto abi : worker) { while (e < dif.size() && abi >= dif[e]) { ++e; }
for (int i = b; i < e; ++i) { lbp = max(pro[i], lbp); }