[LeetCode] Minimum Processing Time

2895. Minimum Processing Time

You have n processors each having 4 cores and n * 4 tasks that need to be executed such that each core should perform only one task.

Given a 0-indexed integer array processorTime representing the time at which each processor becomes available for the first time and a 0-indexed integer array tasks representing the time it takes to execute each task, return the minimum time when all of the tasks have been executed by the processors.

Note: Each core executes the task independently of the others.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int minProcessingTime(vector<int>& A, vector<int>& tasks) {
sort(rbegin(tasks), rend(tasks));
sort(begin(A), end(A));
int res = 0;
while(A.size()) {
for(int i = 0; i < 4; i++) {
int time = A.back() + tasks.back();
res = max(res, time); tasks.pop_back();
}
A.pop_back();
}
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/10/08/PS/LeetCode/minimum-processing-time/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.