cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

restaurant_customers_1619.cpp (507B)


      1 #include <algorithm>
      2 #include <iostream>
      3 #include <queue>
      4 #include <vector>
      5 
      6 int main() {
      7 	size_t n;
      8 	std::cin >> n;
      9 	std::vector<std::pair<int, int>> c(n);
     10 	for (size_t i = 0; i < n; i++) {
     11 		int a, b;
     12 		std::cin >> a >> b;
     13 		c[i] = {a, b};
     14 	}
     15 	std::sort(c.begin(), c.end());
     16 	std::priority_queue<int, std::vector<int>, std::greater<int>> q;
     17 	size_t m{0};
     18 	for (auto d : c) {
     19 		while (!q.empty() && q.top() < d.first) q.pop();
     20 		q.push(d.second);
     21 		m = std::max(m, q.size());
     22 	}
     23 	std::cout << m << "\n";
     24 }