|
1 | 1 | [#0826-most-profit-assigning-work] |
2 | | -= 826. Most Profit Assigning Work |
| 2 | += 826. 安排工作以达到最大收益 |
3 | 3 |
|
4 | | -{leetcode}/problems/most-profit-assigning-work/[LeetCode - Most Profit Assigning Work^] |
| 4 | +https://leetcode.cn/problems/most-profit-assigning-work/[LeetCode - 826. 安排工作以达到最大收益^] |
5 | 5 |
|
6 | | -We have jobs: `difficulty[i]` is the difficulty of the `i`th job, and `profit[i]` is the profit of the `i`th job. |
| 6 | +你有 `n` 个工作和 `m` 个工人。给定三个数组: `difficulty`, `profit` 和 `worker`,其中: |
7 | 7 |
|
8 | | -Now we have some workers. `worker[i]` is the ability of the `i`th worker, which means that this worker can only complete a job with difficulty at most `worker[i]`. |
| 8 | +* `difficulty[i]` 表示第 `i` 个工作的难度,`profit[i]` 表示第 `i` 个工作的收益。 |
| 9 | +* `worker[i]` 是第 `i` 个工人的能力,即该工人只能完成难度小于等于 `worker[i]` 的工作。 |
9 | 10 |
|
10 | | -Every worker can be assigned at most one job, but one job can be completed multiple times. |
| 11 | +每个工人 *最多* 只能安排 *一个* 工作,但是一个工作可以 *完成多次* 。 |
11 | 12 |
|
12 | | -For example, if 3 people attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, his profit is $0. |
| 13 | +* 举个例子,如果 3 个工人都尝试完成一份报酬为 `$1` 的同样工作,那么总收益为 `$3` 。如果一个工人不能完成任何工作,他的收益为 `$0`。 |
13 | 14 |
|
14 | | -What is the most profit we can make? |
| 15 | +返回 _在把工人分配到工作岗位后,我们所能获得的最大利润_。 |
15 | 16 |
|
16 | | -*Example 1:* |
| 17 | +*示例 1:* |
17 | 18 |
|
18 | | -[subs="verbatim,quotes,macros"] |
19 | | ----- |
20 | | -*Input:* difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7] |
21 | | -*Output:* 100 |
22 | | -*Explanation:* Workers are assigned jobs of difficulty [4,4,6,6] and they get profit of [20,20,30,30] seperately. |
23 | | ----- |
| 19 | +.... |
| 20 | +输入: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7] |
| 21 | +输出: 100 |
| 22 | +解释: 工人被分配的工作难度是 [4,4,6,6] ,分别获得 [20,20,30,30] 的收益。 |
| 23 | +.... |
| 24 | + |
| 25 | +*示例 2:* |
| 26 | + |
| 27 | +.... |
| 28 | +输入: difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25] |
| 29 | +输出: 0 |
| 30 | +.... |
24 | 31 |
|
25 | | -*Notes:* |
| 32 | +*提示:* |
26 | 33 |
|
| 34 | +* `n == difficulty.length` |
| 35 | +* `n == profit.length` |
| 36 | +* `m == worker.length` |
| 37 | +* `1 \<= n, m \<= 10^4^` |
| 38 | +* `1 \<= difficulty[i], profit[i], worker[i] \<= 10^5^` |
27 | 39 |
|
28 | | -* `1 <= difficulty.length = profit.length <= 10000` |
29 | | -* `1 <= worker.length <= 10000` |
30 | | -* `difficulty[i], profit[i], worker[i]` are in range `[1, 10^5]` |
31 | 40 |
|
32 | 41 |
|
| 42 | +== 思路分析 |
33 | 43 |
|
| 44 | +先将 `worker` 排序,然后对 `profit` 和 `difficulty` 排序: `profit` 优先,相同则再根据 `difficulty` 排序。从后向前遍历 `worker`,只要 `difficulty` 满足,优先取获利最大的工作。 |
| 45 | + |
| 46 | +TIP: 有点蒙对的感觉。不如题解更有说服力。 |
34 | 47 |
|
35 | 48 | [[src-0826]] |
| 49 | +[tabs] |
| 50 | +==== |
| 51 | +一刷:: |
| 52 | ++ |
| 53 | +-- |
36 | 54 | [{java_src_attr}] |
37 | 55 | ---- |
38 | 56 | include::{sourcedir}/_0826_MostProfitAssigningWork.java[tag=answer] |
39 | 57 | ---- |
| 58 | +-- |
| 59 | +
|
| 60 | +// 二刷:: |
| 61 | +// + |
| 62 | +// -- |
| 63 | +// [{java_src_attr}] |
| 64 | +// ---- |
| 65 | +// include::{sourcedir}/_0826_MostProfitAssigningWork_2.java[tag=answer] |
| 66 | +// ---- |
| 67 | +// -- |
| 68 | +==== |
| 69 | + |
| 70 | + |
| 71 | +== 参考资料 |
40 | 72 |
|
| 73 | +. https://leetcode.cn/problems/most-profit-assigning-work/solutions/2780326/pai-xu-shuang-zhi-zhen-pythonjavacgojsru-gthg/[826. 安排工作以达到最大收益 - 排序+双指针^] |
| 74 | +. https://leetcode.cn/problems/most-profit-assigning-work/solutions/2776977/an-pai-gong-zuo-yi-da-dao-zui-da-shou-yi-c0s1/[826. 安排工作以达到最大收益 - 官方题解^] |
0 commit comments