NOI Carnival
Time limit1sMemory limit512 MB
Place each event at venue A, venue B, or skip it, with no overlapping events split across venues. Maximize the smaller venue's count, with each event forced in turn.
- Level
Hard9 of 10
- Topics
- Intervals, Dynamic programming, Sorting, Graph
- Solved
- No attempts yet
Problem
NOI 2011 has started at Jilin University. To welcome outstanding informatics competitors from across the country, the university will host two carnivals at two different venues. Each venue hosts many events, and each event can be held at only one of the venues.
Andy, the carnival event organizer, has received a total of event applications. The -th event starts at and lasts units of time. Each event may be scheduled at one venue, or it may not be scheduled at all.
If both venues host events at the same time (not counting the instant when an event starts or ends), competitors will be torn between the two venues. To prevent this, no two events may run at both venues simultaneously. Several events may run at the same venue.
A venue with few events will attract few visitors. Andy wants a schedule that maximizes the number of events at the venue with the fewest events.
Some events are especially interesting, and Andy wants to be sure they are held. For each event , find the maximum number of events at the venue with the fewest events, given that event must be held at one of the two venues.
Input
The first line contains an integer , the number of events. Each of the next lines contains two integers and , meaning that event starts at time and lasts units of time.
Output
The first line prints the maximum number of events at the venue with the fewest events, with no extra restrictions. Each of the next lines prints, for event , the maximum number of events at the venue with the fewest events, given that event must be held.
Constraints