본문 바로가기
코딩테스트

백준 회의실배정

by GOMJ 2026. 1. 25.

n이 주어지고 회의 시작시간 종료시간이 주어진다.

 

가장 많이 회의실을 사용하면 몇번이나 사용 가능한지 찾으면 된다.

 

해결은 간단했다. 종료가 가장 빨리 되는 기준으로 회의실 사용을 정렬한뒤 현재 종료시점이 다음 회의실 시작시간보다 같거나 작다면 카운트를 증가시키고 종료시간을 갱신해준다.

 

그러면 최대한 사용 가능

 

#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <math.h>

#define INF 999999999

using namespace std;



int dx[8] = { 1, 0, -1, 0,-1,-1,1,1 };
int dy[8] = { 0, 1, 0, -1,-1,1,-1,1 };
int cnt;
int n, m, t, w;
int dp[300001];
int days[16];
int maxs[16];
//vector<pair<int, int>> node[300001];
vector<int> node[300001];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;


int main() {
	cin >> t;
	vector<pair<int, int>> times;

	int s, e;
	for (int i = 0; i < t; i++) {
		cin >> s >> e;
		times.push_back({ s,e });
	}

	// 종료 시점이 가장 빠른순 정렬
	sort(times.begin(), times.end(), [](const auto& left, const auto& right){
		return left.second < right.second || (left.second == right.second && left.first <= right.first); });

	int time = times[0].second;
	int ans = 1;

	for (int i = 1; i < t; i++)
	{
		if (time <= times[i].first) {
			ans++;
			time = times[i].second; // update end time
		}
	}

	cout << ans << '\n';

	return 0;
}

'코딩테스트' 카테고리의 다른 글

백준 단어 뒤집기2  (0) 2026.02.01
백준 경쟁적 전염  (0) 2026.01.07
백준 촌수계산  (0) 2026.01.01
백준 노드사이의 거리  (0) 2025.12.27
백준 보물섬  (0) 2025.12.21