Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. package weblab;
  2.  
  3. import java.util.*;
  4.  
  5. class Solution {
  6.  
  7. public static /**
  8. * @param n the number of jobs
  9. * @param m the number of processors
  10. * @param deadlines the deadlines of the jobs 1 through n. NB: you should ignore deadlines[0]
  11. * @return the minimised maximum lateness.
  12. */
  13. int solve(int n, int m, int[] deadlines) {
  14. // idk what deadlines 0 is but it works anyway
  15. Arrays.sort(deadlines);
  16.  
  17. Queue<Integer> q = new LinkedList<>();
  18. for (int i = 1; i <= n; i ++) {
  19. System.out.println(deadlines[i]);
  20. q.add(deadlines[i]);
  21. }
  22.  
  23. int maxLateness = 0;
  24. int time = 0;
  25. while (!q.isEmpty()) {
  26. // going hour by hour from 1 until all jobs are done
  27. // because it takes one hour to do a job
  28. time ++;
  29. for (int i = 0; i < m; i++) {
  30. if (!q.isEmpty()) {
  31. int deadline = q.remove();
  32. int lateness = time - deadline;
  33. // ex: if time is 3 and deadline is 2 then we're late
  34. if (deadline < time && maxLateness < lateness) {
  35. maxLateness = lateness;
  36. }
  37. }
  38. }
  39. }
  40. return maxLateness;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement