// Sort by start timepriority_queue<int> pq; // Customized priorityint time =0;for (int i =0; i < N &&pq.size(); ) {if (pq.empty()) time =max(time,A[i][0]); // if no available task, take the starting time of the next taskwhile (i < N &&A[i][0] <= time) pq.push(A[i++][1]); // keep taking in tasks start before/at the current time. // access the pq.top()pq.pop(); // update timewhile (pq.size() &&pq.top() < time) pq.pop(); // evict the tasks that ends before the current time}