Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int scheduleCourse(int[][] courses) {
- Arrays.sort(courses, (a, b) ->
- (a[1] == b[1] ? a[0] - b[0] : a[1] - b[1]));
- int end = 0, re = 0, last = 0;
- Queue<Integer> q = new PriorityQueue<>((a, b)->(b - a));
- for(int[] c : courses)
- {
- if(end + c[0] <= c[1])
- {
- re++;
- end += c[0];
- q.offer(c[0]);
- }
- else if(!q.isEmpty() && q.peek() > c[0])
- {
- // re++;
- end += c[0] - q.poll();
- q.offer(c[0]);
- }
- }
- return re;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement