https://www.acmicpc.net/problem/11000
11000번: 강의실 배정
첫 번째 줄에 N이 주어진다. (1 ≤ N ≤ 200,000) 이후 N개의 줄에 Si, Ti가 주어진다. (1 ≤ Si < Ti ≤ 109)
www.acmicpc.net
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <utility> #include <unordered_map> #include <map> #include <queue> #include <stack> using namespace std; int N; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; priority_queue < pair<int, int>, vector<pair<int, int>>,greater<pair<int,int>>> pq; for (int i = 0; i < N; i++) { int S, T; cin >> S >> T; pq.push(make_pair(S, T)); } priority_queue<int, vector<int>, greater<int>> time; while (!pq.empty()) { pair<int, int> top = pq.top(); pq.pop(); if (time.empty()) { time.push(top.second); } else { if (top.first >= time.top()) { time.pop(); time.push(top.second); } else { time.push(top.second); } } } cout << time.size() << endl; } | cs |
'BAEKJOON ONLINE JUDGE' 카테고리의 다른 글
[백준 15922] 아우으 우아으이야!! (C++) (0) | 2021.08.27 |
---|---|
[백준 13164] 행복 유치원 (C++) (0) | 2021.08.27 |
[백준 21611] 마법사 상어와 블리자드 (C++) (0) | 2021.08.26 |
[백준 20061] 모노미노도미노 2 (C++) (0) | 2021.08.23 |
[백준 21609] 상어 중학교 (C++) (0) | 2021.08.22 |