현재 시간을 늘려가면서 시작할 강의는 시작하고 끝낼 강의는 끝내기
1. 현재 강의중 큐에서 종료시간과 현재 시간 동일한 강의 있으면 pop 하기
2-1. 강의 대기 큐에서 시작시간과 현재 시간 동일한 강의 있으면 pop 하고 현재 강의중 큐에 push 하기
2-2. 현재 강의중인 큐가 강의실 개수보다 많거나 크면 강의실 추가하기
시간초과 심각하고 답도 틀림
pair 큐를 2개로 돌리고 시간 count 를 따로 하면 반복문을 중첩으로 돌려야하기 때문에 비효율적
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct cmp {
bool operator()(pair<int,int> a, pair<int,int> b) {
if(a.first==b.first) return a.second>b.second;
return a.first>b.first;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> wait;
priority_queue<int,vector<int>,greater<>> fin;
cin >> n;
while(n--) {
int s,t;
cin >> s >> t;
wait.push({s,t});
}
fin.push(wait.top().second);
wait.pop();
while (!wait.empty()) {
// 강의실 추가
if(wait.top().first>=fin.top()) fin.pop();
fin.push(wait.top().second);
wait.pop();
}
cout << fin.size() << endl;
}