https://www.acmicpc.net/problem/11000
그리디 문제.
문제 접근
강의들 중 연결시킬 수 있는 것들은 최대한 연결시켜야 하기 때문에,
끝나는 시각 우선순위 큐, 시작 시간 우선 순위 큐를 사용하여
먼저 시작하는 회의들을 차근차근 시작한다.
이때 만약 끝나는 시각 우선 순위 큐의 top에 현재 시작 시각보다
빠르거나 같은 끝나는 시간이 있으면 그 회의실에 이어질 수 있도록
알고리즘을 구상했다.
코드는 다음과 같다.
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin >> n;
pair<int, int> tmp;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
priority_queue<int,vector<int>, greater<int>> e;
for(int i=0;i<n;i++){cin >> tmp.first >> tmp.second;pq.push({tmp.first, tmp.second});}
e.push(pq.top().second);
pq.pop();
int ans=1;
while(!pq.empty()){
if(pq.top().first>=e.top()) e.pop();
else ans++;
e.push(pq.top().second);
pq.pop();
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
solve();
}