-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay63.java
More file actions
33 lines (32 loc) · 1.15 KB
/
Day63.java
File metadata and controls
33 lines (32 loc) · 1.15 KB
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
import java.util.Arrays;
public class Day63 {
public static int[] getMaxProfitJobs(int[][] jobs) {
Arrays.sort(jobs, (a, b) -> Integer.compare(b[2], a[2]));
int maxDeadline = 0;
for (int[] job : jobs) {
maxDeadline = Math.max(maxDeadline, job[1]);
}
boolean[] slots = new boolean[maxDeadline];
int totalProfit = 0;
int count = 0;
for (int[] job : jobs) {
for (int j = Math.min(maxDeadline - 1, job[1] - 1); j >= 0; j--) {
if (!slots[j]) {
slots[j] = true;
totalProfit += job[2];
count++;
break;
}
}
}
return new int[]{count, totalProfit};
}
public static void main(String[] args) {
int[][] jobs1 = {{1, 2, 30}, {2, 2, 40}, {3, 1, 10}, {4, 1, 10}};
int[] result1 = getMaxProfitJobs(jobs1);
System.out.println(Arrays.toString(result1));
int[][] jobs2 = {{1, 1, 40}, {2, 1, 50}, {3, 1, 60}};
int[] result2 = getMaxProfitJobs(jobs2);
System.out.println(Arrays.toString(result2));
}
}