luogu#P16380. [NordicOI 2026] Catching Apples

    ID: 16508 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>Special Judge2026Dilworth 定理NordicOI(北欧)

[NordicOI 2026] Catching Apples

Problem Description

An apple orchard is represented as a one-dimensional line. There are NN apples, and apple ii falls at time tit_i at position xix_i.

A robot can move at speed at most 11. To catch apple ii, a robot must be exactly at position xix_i at time tit_i. 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 NN (1N21051 \leq N \leq 2 \cdot 10^5), the number of apples.

The following NN lines each contain two integers tit_i and xix_i (1ti,xi1091 \leq t_i, x_i \leq 10^9), the time and position of apple ii.

All pairs (ti,xi)(t_i, x_i) are distinct.

Output Format

Print one integer KK, the minimum number of robots needed to catch all apples.

Then print NN integers a1,a2,,aNa_1, a_2, \dots, a_N on the next line, where aia_i is the id of the robot that catches apple ii.

The ids must be between 11 and KK, and every id from 11 to KK 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 KK.

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.

子任务 分值 附加限制
11 1515 N20N \leq 20
22 1313 The minimum number of robots needed is at most 22.
33 2020 N5000N \leq 5000
44 2727 No plan needs to be given, only the number of robots.
55 2525 No additional constraints.

Explanation of Sample

In the first sample, one robot can catch every apple in order.

In the second sample, apples 11 and 33 can be caught by the same robot, but apple 22 must be caught by a different robot.

In the third sample, the minimum number of robots is 22, but there are several different optimal assignments.