You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2300-2399/2323.Find Minimum Time to Finish All Jobs II/README_EN.md
+66-7
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,13 @@ It can be proven that 3 days is the minimum number of days needed.
67
67
68
68
<!-- solution:start -->
69
69
70
-
### Solution 1
70
+
### Solution 1: Greedy
71
+
72
+
To minimize the number of days required to complete all jobs, we can try to assign longer jobs to workers who can work longer hours.
73
+
74
+
Therefore, we can first sort $\textit{jobs}$ and $\textit{workers}$, then assign jobs to workers based on their indices. Finally, we calculate the maximum ratio of job time to worker time.
75
+
76
+
The time complexity is $O(n \log n)$, and the space complexity is $O(\log n)$. Here, $n$ is the number of jobs.
71
77
72
78
<!-- tabs:start -->
73
79
@@ -103,10 +109,13 @@ class Solution {
103
109
classSolution {
104
110
public:
105
111
int minimumTime(vector<int>& jobs, vector<int>& workers) {
106
-
sort(jobs.begin(), jobs.end());
107
-
sort(workers.begin(), workers.end());
112
+
ranges::sort(jobs);
113
+
ranges::sort(workers);
108
114
int ans = 0;
109
-
for (int i = 0; i < jobs.size(); ++i) ans = max(ans, (jobs[i] + workers[i] - 1) / workers[i]);
115
+
int n = jobs.size();
116
+
for (int i = 0; i < n; ++i) {
117
+
ans = max(ans, (jobs[i] + workers[i] - 1) / workers[i]);
0 commit comments