알고리즘/풀이
백준 1931번: 회의실 배정 - C++
개발하는 민우
2022. 2. 26. 03:30
[문제]
https://www.acmicpc.net/problem/1931
1931번: 회의실 배정
(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.
www.acmicpc.net
[풀이]
그리디 알고리즘
[코드]
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> s[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=0; i<n; i++) {
cin >> s[i].second >> s[i].first;
}
sort(s, s+n);
int ans=0;
int t=0;
for(int i=0; i<n; i++){
if(t > s[i].second) continue;
ans++;
t = s[i].first;
}
cout << ans;
}