826. Most Profit Assigning Work
Medium
You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:
Every worker can be assignedat most one job, but one job can becompleted multiple times.
Returnthe maximum profit we can achieve after assigning the workers to the jobs.
Example 1:
Example 2:
Constraints:
Solution:
class Solution { /** * @param Integer[] $difficulty * @param Integer[] $profit * @param Integer[] $worker * @return Integer */ function maxProfitAssignment($difficulty, $profit, $worker) { $ans = 0; $jobs = array(); for ($i = 0; $i < count($difficulty); ++$i) { $jobs[] = array($difficulty[$i], $profit[$i]); } sort($jobs); sort($worker); $i = 0; $maxProfit = 0; foreach ($worker as $w) { for (; $i < count($jobs) && $w >= $jobs[$i][0]; ++$i) { $maxProfit = max($maxProfit, $jobs[$i][1]); } $ans += $maxProfit; } return $ans; } }Contact Links
The above is the detailed content of . Most Profit Assigning Work. For more information, please follow other related articles on the PHP Chinese website!