2895. Minimum Processing Time Medium

@problem@discussion
#Array#Greedy#Sorting



1/**
2 * [2895] Minimum Processing Time
3 *
4 * You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task must be assigned to a unique core, and each core can only be used once.
5 * You are given an array processorTime representing the time each processor becomes available and an array tasks representing how long each task takes to complete. Return the minimum time needed to complete all tasks.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]</span>
10 * Output: <span class="example-io">16</span>
11 * Explanation:
12 * Assign the tasks at indices 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indices 0, 1, 2, 3 to the second processor which becomes available at time = 10. 
13 * The time taken by the first processor to finish the execution of all tasks is max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.
14 * The time taken by the second processor to finish the execution of all tasks is max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]</span>
19 * Output: <span class="example-io">23</span>
20 * Explanation:
21 * Assign the tasks at indices 1, 4, 5, 6 to the first processor and the others to the second processor.
22 * The time taken by the first processor to finish the execution of all tasks is max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.
23 * The time taken by the second processor to finish the execution of all tasks is max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.
24 * </div>
25 *  
26 * Constraints:
27 * 
28 * 	1 <= n == processorTime.length <= 25000
29 * 	1 <= tasks.length <= 10^5
30 * 	0 <= processorTime[i] <= 10^9
31 * 	1 <= tasks[i] <= 10^9
32 * 	tasks.length == 4 * n
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/minimum-processing-time/
38// discuss: https://leetcode.com/problems/minimum-processing-time/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn min_processing_time(processor_time: Vec<i32>, tasks: Vec<i32>) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2895() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.