Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package weblab;
- import java.util.*;
- class Solution {
- public static /**
- * @param n the number of jobs
- * @param m the number of processors
- * @param deadlines the deadlines of the jobs 1 through n. NB: you should ignore deadlines[0]
- * @return the minimised maximum lateness.
- */
- int solve(int n, int m, int[] deadlines) {
- // idk what deadlines 0 is but it works anyway
- Arrays.sort(deadlines);
- Queue<Integer> q = new LinkedList<>();
- for (int i = 1; i <= n; i ++) {
- System.out.println(deadlines[i]);
- q.add(deadlines[i]);
- }
- int maxLateness = 0;
- int time = 0;
- while (!q.isEmpty()) {
- // going hour by hour from 1 until all jobs are done
- // because it takes one hour to do a job
- time ++;
- for (int i = 0; i < m; i++) {
- if (!q.isEmpty()) {
- int deadline = q.remove();
- int lateness = time - deadline;
- // ex: if time is 3 and deadline is 2 then we're late
- if (deadline < time && maxLateness < lateness) {
- maxLateness = lateness;
- }
- }
- }
- }
- return maxLateness;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement