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<intint>vector<pair<intint>>,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<intvector<int>, greater<int>> time;
    while (!pq.empty()) {
        pair<intint> 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

+ Recent posts