Course Schedule III(heap,sort)
There aren
different online courses numbered from1
ton
. Each course has some duration(course length)t
and closed ondth
day. A course should be takencontinuouslyfort
days and must be finished before or on thedth
day. You will start at the1st
day.
Givenn
online courses represented by pairs(t,d)
, your task is to find the maximal number of courses that can be taken.
Example:
Note: The integer 1
The integer 1<= d, t, n <= 10,000.
You can't take two courses simultaneously.
分析
看到数组先排序,按照日期(c[1])从小到大。 用priority queue存耗费天数 c[0],按照从大小大。然后loop每个课程,都加入pq算天数。遇到不行的就从pq里弹出最大c[0]。
Last updated