PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000051. Phân phòng khách sạn (Room Allocation)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phân phòng khách sạn (Room Allocation)
Room Allocation
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
There are hotel guests, each staying from arrival day through departure day , inclusive. Guests can reuse a room only if the first guest departs strictly before the next arrives. Find the minimum number of rooms and assign each original guest a room.
Input
The first line gives , followed by pairs indicating arrival and departure days.
Output
Print the minimum room count , then one room number between and for each guest in input order. Any valid optimal assignment is accepted.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
1 2
2 4
4 4
Output
2
1 2 1
Explanation
Guests 1 and 2 both need rooms on day 2, so at least two rooms are necessary. Guest 3 arrives after guest 1 leaves and may reuse room 1.