luogu#P16380. [NordicOI 2026] Catching Apples
[NordicOI 2026] Catching Apples
Problem Description
An apple orchard is represented as a one-dimensional line. There are apples, and apple falls at time at position .
A robot can move at speed at most . To catch apple , a robot must be exactly at position at time . Each robot may start at any position, and after catching its last apple it may end anywhere.
Your task is to catch all apples using as few robots as possible. You must also output which robot catches each apple.
Input Format
The first line contains one integer (), the number of apples.
The following lines each contain two integers and (), the time and position of apple .
All pairs are distinct.
Output Format
Print one integer , the minimum number of robots needed to catch all apples.
Then print integers on the next line, where is the id of the robot that catches apple .
The ids must be between and , and every id from to must be used at least once.
If there are multiple optimal assignments, you may output any of them.
For Group 4 only, it is also allowed to print only the integer .
4
1 1
3 2
5 3
8 1
1
1 1 1 1
3
1 1
2 5
3 1
2
1 2 1
4
2 2
3 1
3 3
4 2
2
1 1 2 1
Hint
Scoring
Your solution will be tested on a set of test groups. To earn points for a group, you must pass all test cases in that group.
| 子任务 | 分值 | 附加限制 |
|---|---|---|
| The minimum number of robots needed is at most . | ||
| No plan needs to be given, only the number of robots. | ||
| No additional constraints. |
Explanation of Sample
In the first sample, one robot can catch every apple in order.
In the second sample, apples and can be caught by the same robot, but apple must be caught by a different robot.
In the third sample, the minimum number of robots is , but there are several different optimal assignments.