Posted on

Description

Submission

class Solution {
public:
    int maxEvents(vector<vector<int>>& events) {
        sort(events.begin(), events.end());
        priority_queue<int, vector<int>, greater<>> pq;

        int ret = 0;
        int ptr = 0;

        for(int day = 1; day <= 1e5; ++day) {
            

            while(ptr < events.size() && events[ptr][0] <= day) {
                pq.push(events[ptr][1]);
                ++ptr;
            }

            while(!pq.empty() && pq.top() < day) {
                pq.pop();
            }

            if(!pq.empty()) {
                pq.pop();
                ++ret;
            }
        }

        return ret;
    }
};

// sort by start time, push ddl into the pq when startDay reaches, ddl ealiest first
// remove the expired ddls each time

Leave a Reply

Your email address will not be published. Required fields are marked *