-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
630.py
33 lines (32 loc) · 1.18 KB
/
630.py
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
__________________________________________________________________________________________________
sample 776 ms submission
class Solution:
def scheduleCourse(self, courses: List[List[int]]) -> int:
import heapq
totalLen = 0
heap = []
for t, d in sorted(courses, key=lambda x: x[1]):
if totalLen + t <= d:
totalLen += t
heapq.heappush(heap, -t)
elif heap and t < -heap[0]:
totalLen += t + heapq.heappop(heap)
heapq.heappush(heap, -t)
return len(heap)
__________________________________________________________________________________________________
sample 16624 kb submission
class Solution:
def scheduleCourse(self, courses):
courses.sort(key=lambda x:x[1])
he,s=[],0
heapq.heappush(he,0)
for t,d in courses:
if s+t>d:
if t+he[0]<0:
s+=t+he[0]
heapq.heappushpop(he,-t)
else:
s+=t
heapq.heappush(he,-t)
return len(he)-1
__________________________________________________________________________________________________