Участник:Alexryabov/TaskCourseScheduleiii

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/course-schedule-iii

from heapq import heappush, heappop
class Solution(object):
    def scheduleCourse(self, courses):
        courses.sort(key=lambda course: course[1]) 
        priority_queue=[]
        current_time=0 
        for time,duration in courses:
            heappush(priority_queue,-time) 
            current_time+=time 
            if current_time>duration: current_time+=heappop(priority_queue)
        return len(priority_queue)