#P1973. [NOI2011] NOI 嘉年华

    ID: 919 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2011单调队列NOI 系列Special Judge

[NOI2011] NOI 嘉年华

Description

NOI 2011 has started at Jilin University! To welcome the best informatics contestants from across the country, Jilin University plans to hold two grand NOI Carnival events at two different locations. Each carnival may contain many activities, and each activity can be held in only one carnival.

The organizer, Xiao An, has received nn applications for activities. The ii-th activity starts at time SiS_i and lasts for TiT_i time. These activities can be scheduled in either carnival, or not scheduled at all.

Through extensive surveys, Xiao An found that if, at some moment, the two carnivals have activities running simultaneously (not counting the exact start and end instants), some contestants will hesitate about which carnival to go to and become unhappy. Therefore, to avoid this, Xiao An requires that there must not be two activities running at the same time in the two different carnivals (activities within the same carnival may overlap arbitrarily).

In addition, if one carnival has too few activities, its appeal will be insufficient and the scene may become dull. So Xiao An wants to arrange the schedule to maximize the number of activities in the less-populated carnival.

Furthermore, some activities are very meaningful and Xiao An hopes to hold them. He wants to know, if the ii-th activity must be held (it can be scheduled in either of the two carnivals), what is the maximum number of activities in the less-populated carnival.

Input Format

The first line contains an integer nn, the number of activity applications.

The next nn lines describe all activities. The ii-th line contains two integers Si,TiS_i, T_i, meaning the ii-th activity starts at time SiS_i and lasts for TiT_i time.

Output Format

The first line contains an integer, the maximum number of activities in the less-populated carnival when there are no additional constraints.

Then output nn lines, one integer per line. The integer on the ii-th line is the maximum number of activities in the less-populated carnival under the condition that the ii-th activity must be chosen.

5 
8 2 
1 5 
5 3 
3 2 
5 3 
2 
2 
1 
2 
2 
2 

Hint

Sample Explanation

Without any additional constraints, an optimal arrangement is to schedule activities 1,41, 4 in one carnival and activities 3,53, 5 in the other carnival, leaving activity 22 unscheduled.

For 10% of the testdata, 1n101 \leq n \leq 10.

For 30% of the testdata, 1n401 \leq n \leq 40.

For 100% of the testdata, 1n2001 \leq n \leq 200, 0Si1090 \leq S_i \leq 10^9, 1Ti1091 \leq T_i \leq 10^9.

If the output format is incorrect (for example, fewer than n+1n+1 lines), the score is 00. If the first line of the output file is incorrect, and at least one of the last nn lines is also incorrect, the score is 00. If the first line of the output file is correct, but at least one of the last nn lines is incorrect, the score is 44. If the first line of the output file is incorrect, but all of the last nn lines are correct, the score is 66. If all n+1n+1 lines in the output file are correct, the score is 1010.

Translated by ChatGPT 5