#include <bits/stdc++.h>
using namespace std;
// book a room for meeting and return the name of the room booked
// History of meetings booked
// api which string meeting_room_scheduled(start,end)
// -->if already booked
//     a.) change room
//     b.) change timings
class Meeting;
class Room;
bool clash(vector<int> a, vector<int> b)
{
    return max(a[0], b[0]) <= min(a[1], b[1]);
}

class Meeting
{
private:
    int start, end;
    Room *room;

public:
    Meeting(int _start, int _end, Room *_room)
    {
        start = _start;
        end = _end;
        room = _room;
    }
    vector<int> get_interval()
    {
        vector<int> x = {start, end};
        return x;
    }
};
class Room
{
private:
    string name;
    vector<Meeting> calendar;

public:
    Room()
    {
        name = "";
        calendar = vector<Meeting>();
    }
    Room(string _name)
    {
        name = _name;
        calendar = vector<Meeting>();
    }
    string get_name()
    {
        return name;
    }
    vector<Meeting> get_calendar()
    {
        return calendar;
    }
    bool book(int _start, int _end)
    {
        vector<int> new_interval = {_start, _end};
        bool ok = true;
        for (Meeting &i : calendar)
        {
            vector<int> temp = i.get_interval();
            if (clash(temp, new_interval))
                ok = false;
        }
        if (ok == false)
            return false;
        calendar.push_back(Meeting(_start, _end, this));
        //cout<<calendar.size()<<"\n";
        return true;
    }
};

class Scheduler
{
public:
    vector<Room> rooms;
    bool book(int start, int end, string room_id)
    {
        if(start>=end)
            return false;
        for (auto &i : rooms)
        {
            if (i.get_name() == room_id && i.book(start, end))
            {
                return true;
            }
        }
        return false;
    }
};
void print(Room room)
{
    auto x=room.get_calendar();
    for(auto j: x)
    {
        cout<<j.get_interval()[0]<<" "<<j.get_interval()[1]<<"\n";
    }
}
int main()
{
    Scheduler scheduler;
    for (int i = 0; i < 5; i++)
    {
        string name = "x" + to_string(i);
        scheduler.rooms.push_back(Room(name));
    }
    if (scheduler.book(1, 10, "x1"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }

    if (scheduler.book(4, 10, "x1"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }
    if (scheduler.book(18, 19, "x1"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }
    if (scheduler.book(1, 111, "x1"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }
    if (scheduler.book(41, 42, "x1"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }
    if (scheduler.book(1, 2, "x2"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }

    if (scheduler.book(4, 10, "x2"))
    {
        cout << "[SUCCESS]: Meeting scheduled successfully\n";
    }
    else
    {
        cout << "[ERROR]: Unexpected error\n";
    }

    print(scheduler.rooms[1]);
    cout<<"===\n";
    print(scheduler.rooms[2]);

    return 0;
}