이번 문제는 pair와 우선순위 큐를 사용하여 해결했다.
#include <iostream>
#include <queue>
#include <algorithm>
#define MAX 200001
using namespace std;
int n;
int a, b;
pair<int, int> p[MAX];
priority_queue<int, vector<int>, greater<int>> pq;
int classroom=0;
void Input(){
cin>>n;
for(int i=0; i<n; i++){
cin>>p[i].first>>p[i].second;
}
}
void Solution(){
sort(p, p+n);
pq.push(p[0].second);
for(int i=1; i<n; i++){
if(pq.top()<=p[i].first){
pq.pop();
pq.push(p[i].second);
}
else{
pq.push(p[i].second);
}
}
classroom=(int)pq.size();
cout<<classroom<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
Input();
Solution();
return 0;
}