-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimumWorkPerDay.java
More file actions
35 lines (28 loc) · 974 Bytes
/
MinimumWorkPerDay.java
File metadata and controls
35 lines (28 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Arrays;
public class MinimumWorkPerDay {
public static int minWork(int[] tasks, int d) {
Arrays.sort(tasks);
if (tasks.length <= d) {
return tasks[tasks.length - 1];
}
int totalDays = d;
int maxWork = tasks[tasks.length - 1];
for (int i = tasks.length - 2; i >= 0; i--) {
if (totalDays > 1) {
totalDays--;
maxWork = Math.max(maxWork, tasks[i]);
} else {
maxWork += tasks[i];
}
}
return maxWork;
}
public static void main(String[] args) {
int[] tasks1 = {3, 4, 7, 15};
int d1 = 10;
System.out.println("Minimum work per day for tasks1: " + minWork(tasks1, d1));
int[] tasks2 = {30, 20, 22, 4, 21};
int d2 = 6;
System.out.println("Minimum work per day for tasks2: " + minWork(tasks2, d2));
}
}