BAEKJOON/C++

[B1931][회의실 배정][C++]

sseni 2021. 6. 15. 14:52
728x90

https://www.acmicpc.net/problem/1931


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n, s, f;
vector<pair<int, int>> v;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s >> f;
		v.push_back(make_pair(f, s)); // (끝, 시작)
	}

	sort(v.begin(), v.end());
	int t = v[0].first; // 끝나는 시간
	int cnt = 1; 
	for (int i = 1; i < n; i++) {
		if (t <= v[i].second) { 
			cnt++;
			t = v[i].first;
		}
	}
	cout << cnt;
}
728x90