826. Most Profit Assigning Work Medium

@problem@discussion
#Array#Two Pointers#Binary Search#Greedy#Sorting



1/**
2 * [826] Most Profit Assigning Work
3 *
4 * You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:
5 * 
6 * 	difficulty[i] and profit[i] are the difficulty and the profit of the i^th job, and
7 * 	worker[j] is the ability of j^th worker (i.e., the j^th worker can only complete a job with difficulty at most worker[j]).
8 * 
9 * Every worker can be assigned at most one job, but one job can be completed multiple times.
10 * 
11 * 	For example, if three workers attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, their profit is $0.
12 * 
13 * Return the maximum profit we can achieve after assigning the workers to the jobs.
14 *  
15 * Example 1:
16 * 
17 * Input: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]
18 * Output: 100
19 * Explanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get a profit of [20,20,30,30] separately.
20 * 
21 * Example 2:
22 * 
23 * Input: difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25]
24 * Output: 0
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	n == difficulty.length
30 * 	n == profit.length
31 * 	m == worker.length
32 * 	1 <= n, m <= 10^4
33 * 	1 <= difficulty[i], profit[i], worker[i] <= 10^5
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/most-profit-assigning-work/
39// discuss: https://leetcode.com/problems/most-profit-assigning-work/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn max_profit_assignment(difficulty: Vec<i32>, profit: Vec<i32>, worker: Vec<i32>) -> i32 {
45        0
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_826() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.