CSES - Room Allocation

Author: Shreyas Thumathy

Table of Contents

Main Idea
Edit on Github

In this problem, we're asked the minimum number of rooms needed to accommodate customers, which arrive and leave on set days.

Main Idea

  • First Step: Sort by arrival time (we cannot have a customer arriving at say, time 3, occupying a room before a customer arriving at time 2).
  • Second Step: Maintain a minimum heap which stores the time a hotel room will be unoccupied.
    • Every time a new customer arrvies, we check to see if the minimum element in the heap is less than the arrival time of the new customer.
    • If this is true, we can just switch the times.
    • If not, then we need to add another room to the heap.
1#include <iostream>
2#include <algorithm>
3#include <queue>
4using namespace std;
5
6
7int N;
8int ans[200005];
9vector<pair<pair<int, int>, int> > v(200005);
10

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on CSES - Room Allocation!