Skip to content

Commit 1772ea4

Browse files
committed
[Gold V] Title: 최소 회의실 개수, Time: 124 ms, Memory: 3572 KB -BaekjoonHub
1 parent a18685b commit 1772ea4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [Gold V] 최소 회의실 개수 - 19598
2+
3+
[문제 링크](https://www.acmicpc.net/problem/19598)
4+
5+
### 성능 요약
6+
7+
메모리: 3572 KB, 시간: 124 ms
8+
9+
### 분류
10+
11+
자료 구조, 그리디 알고리즘, 우선순위 큐, 정렬, 스위핑
12+
13+
### 제출 일자
14+
15+
2025년 3월 9일 16:54:49
16+
17+
### 문제 설명
18+
19+
<p>서준이는 아빠로부터 N개의 회의를 모두 진행할 수 있는 최소 회의실 개수를 구하라는 미션을 받았다. 각 회의는 시작 시간과 끝나는 시간이 주어지고 한 회의실에서 동시에 두 개 이상의 회의가 진행될 수 없다. 단, 회의는 한번 시작되면 중간에 중단될 수 없으며 한 회의가 끝나는 것과 동시에 다음 회의가 시작될 수 있다. 회의의 시작 시간은 끝나는 시간보다 항상 작다. N이 너무 커서 괴로워 하는 우리 서준이를 도와주자.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 배열의 크기 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N+1 줄까지 공백을 사이에 두고 회의의 시작시간과 끝나는 시간이 주어진다. 시작 시간과 끝나는 시간은 2<sup>31</sup>−1보다 작거나 같은 자연수 또는 0이다.</p>
24+
25+
### 출력
26+
27+
<p>첫째 줄에 최소 회의실 개수를 출력한다.</p>
28+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
#include <algorithm>
5+
6+
using namespace std;
7+
8+
vector<pair<int, int> > v;
9+
priority_queue<int, vector<int>, greater<int> > pq;
10+
11+
int main() {
12+
int N;
13+
cin >> N;
14+
for (int i = 0; i < N; i++) {
15+
int start, end;
16+
cin >> start >> end;
17+
v.emplace_back(start, end);
18+
}
19+
sort(v.begin(), v.end());
20+
pq.push(v[0].second); // 시작 시간이 가장 낮은 회의의 끝 시간 넣기
21+
22+
int ans = 1;
23+
for (int i = 1; i < N; i++) {
24+
while (!pq.empty() && pq.top() <= v[i].first) {
25+
pq.pop(); // 기존 회의 끝나서 pq에서 빼주기
26+
}
27+
pq.push(v[i].second); // pq에 다음 회의 넣어주기
28+
ans = max(ans, static_cast<int>(pq.size()));
29+
}
30+
31+
cout << ans;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)