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

 

1374번: 강의실

첫째 줄에 강의의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에 걸쳐 각 줄마다 세 개의 정수가 주어지는데, 순서대로 강의 번호, 강의 시작 시간, 강의 종료 시간을 의미한다. 강의

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
41
42
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
using namespace std;
// 1374 강의실
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    priority_queue<pair<intint>vector<pair<intint>>, greater<pair<intint>>> pq;
    priority_queue<intvector<int>, greater<int>> tq;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int num, st, ed;
        cin >> num >> st >> ed;
        pq.push(make_pair(st, ed));
    }
    while (!pq.empty()) {
        pair<intint> pre = pq.top();
        pq.pop();
        if (tq.empty()) {
            tq.push(pre.second);
        }
        else {
            if (pre.first >= tq.top()) {
                tq.pop();
                tq.push(pre.second);
            }
            else {
                tq.push(pre.second);
            }
        }
    }
    cout << tq.size();
}
cs

+ Recent posts