끄적끄적
백준 [11000] 강의실 배정 본문
출처 : https://www.acmicpc.net/problem/11000
11000번: 강의실 배정
첫 번째 줄에 N이 주어진다. (1 ≤ N ≤ 200,000) 이후 N개의 줄에 Si, Ti가 주어진다. (0 ≤ Si < Ti ≤ 109)
www.acmicpc.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<queue> | |
#include<vector> | |
#include<algorithm> | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false); | |
cin.tie(0); | |
cout.tie(0); | |
int N, S, T; | |
priority_queue<int, vector<int>, greater<int>> pq; | |
vector<pair<int, int>> v; | |
cin >> N; | |
for (int i = 0; i < N; i++) { | |
cin >> S >> T; | |
v.push_back({ S, T }); | |
} | |
sort(v.begin(), v.end()); | |
for (int i = 0; i < N; i++) { | |
if (pq.empty()) pq.push(v[i].second); | |
else { | |
int fin = pq.top(); | |
if (v[i].first >= fin) pq.pop(); | |
pq.push(v[i].second); | |
} | |
} | |
cout << pq.size() << '\n'; | |
return 0; | |
} |
우선순위큐
vector에 입력된 값을 정렬하지 않고 풀었더니 틀렸다고 떠서 정렬을 해주었다.
끝난 시간도 우선순위큐에 넣음으로써 정렬시켜주지만, 시작시간도 먼저 시작된 순으로 들어가야하기 때문에 벡터 정렬을 해줘야 하는 것 같다.
'코테준비 > 백준' 카테고리의 다른 글
백준 [20166] 문자열 지옥에 빠진 호석 (0) | 2022.08.16 |
---|---|
백준 [13904] 과제 (0) | 2022.08.15 |
백준 [2002] 추월 (0) | 2022.08.13 |
백준 [15903] 카드 합체 놀이 (0) | 2022.08.13 |
백준 [10546] 배부른 마라토너 (0) | 2022.08.12 |