AdvancedRating 1700
Rooms for Every Guest
Guests arrive and leave on given days (a guest leaving on day d frees the room for someone arriving on day d + 1, not on day d). Assign rooms so that no two guests share a room at the same time, using as few rooms as possible. Print the number of rooms, then each guest's room number (rooms 1, 2, …; always give the free room with the smallest number).
Input
n; then n lines 'arrive leave'.
Output
The room count, then n room numbers on one line.
Sample 1
Input
3 1 2 2 4 4 4
Output
2 1 2 1
Sample 2
Input
2 1 1 2 2
Output
1 1 1
Output appears here