Room Allocation
#1164Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude DesktopThere is a large hotel, and customers will arrive soon. Each customer wants to have a single room.
You know each customer's arrival and departure day. Two customers can stay in the same room if the departure day of the first customer is earlier than the arrival day of the second customer.
What is the minimum number of rooms that are needed to accommodate all customers? And how can the rooms be allocated?
Input
The first input line contains an integer : the number of customers.
Then there are lines, each of which describes one customer. Each line has two integers and : the arrival and departure day.
Output
Print first an integer : the minimum number of rooms required.
After that, print a line that contains the room number of each customer in the same order as in the input. The rooms are numbered . You can print any valid solution.
3 1 2 2 4 4 4
2 1 2 1
Tools
3 1 2 2 4 4 4
2 1 2 1