Home BOJ. Lecture Room Assignment (11000)
Post
Cancel

BOJ. Lecture Room Assignment (11000)

[Link] https://www.acmicpc.net/problem/11000


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
43
44
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "

const int MAX = 5e5 + 1;
int n;

bool cmp(pair<int, bool> pl, pair<int, bool> pr) {
  if(pl.first == pr.first) return pl.second == pr.second ? false : (!pl.second || pr.second);
  return pl.first < pr.first;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n;
  vector<pair<int, bool>> schedule;
  for0(i, n) {
    int s, t; cin >> s >> t;
    schedule.push_back({ s, true });
    schedule.push_back({ t, false });
  }
  sort(schedule.begin(), schedule.end(), cmp);
  int cnt = 0, max_val = 0;
  for(auto e: schedule) {
    if(e.second) cnt++;
    else cnt--;
    max_val = max(max_val , cnt);
  }
  cout << max_val;
  return 0;
}
This post is licensed under CC BY 4.0 by the author.