Insert the end day of the jobs which can be completed on i - th day in a priority queue
while ( index < ranges . Count && ranges [ index ] . Item1 <= i ) { queue . Add ( ranges [ index ] . Item2 ) ; index ++ ; } queue . Sort ( ) ;