forked from CodeGraphContext/CodeGraphContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobSequencing.java
More file actions
40 lines (34 loc) · 1.03 KB
/
Copy pathJobSequencing.java
File metadata and controls
40 lines (34 loc) · 1.03 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
34
35
36
37
38
39
40
import java.util.*;
public class JobSequencing {
static class Job{
int deadline;
int profit;
int id;
public Job(int i, int d, int p){
id = i;
deadline = d;
profit = p;
}
}
public static void main(String args[]){
int jobsInfo[][] = {{4,20},{1,10},{1,40},{1,30}};
ArrayList<Job> jobs = new ArrayList<>();
for(int i =0; i<jobsInfo.length;i++){
jobs.add(new Job(i,jobsInfo[i][0],jobsInfo[i][1]));
}
Collections.sort(jobs, (obj1,obj2) -> obj2.profit - obj1.profit);
ArrayList<Integer>seq = new ArrayList<>();
int time = 0;
for(int i = 0; i<jobs.size();i++){
Job curr = jobs.get(i);
if(curr.deadline > time){
seq.add(curr.id);
time++;
}
}
System.out.println("max jobs =" + seq.size());
for(int i = 0; i<seq.size();i++){
System.out.println(seq.get(i)+" ");
}
}
}