QOJ.ac

QOJ

実行時間制限: 3.0 s メモリ制限: 1024 MB 満点: 100

#17625. Catching Apples

統計

An apple orchard is represented as a one-dimensional line. There are $N$ apples, and apple $i$ falls at time $t_i$ at position $x_i$.

A robot can move at speed at most $1$. To catch apple $i$, a robot must be exactly at position $x_i$ at time $t_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

The first line contains one integer $N$ ($1 \leq N \leq 2 \cdot 10^5$), the number of apples.

The following $N$ lines each contain two integers $t_i$ and $x_i$ ($1 \leq t_i, x_i \leq 10^9$), the time and position of apple $i$.

All pairs $(t_i, x_i)$ are distinct.

Output

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

Then print $N$ integers $a_1, a_2, \dots, a_N$ on the next line, where $a_i$ is the id of the robot that catches apple $i$.

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

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.

Group Points Constraints
$1$ $15$ $N \leq 20$
$2$ $13$ The minimum number of robots needed is at most $2$.
$3$ $20$ $N \leq 5000$
$4$ $27$ No plan needs to be given, only the number of robots.
$5$ $25$ No additional constraints.

Sample Input 1

4
1 1
3 2
5 3
8 1

Sample Output 1

1
1 1 1 1

Sample Input 2

3
1 1
2 5
3 1

Sample Output 2

2
1 2 1

Sample Input 3

4
2 2
3 1
3 3
4 2

Sample Output 3

2
1 1 2 1

Explanation of Samples

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

In the second sample, apples $1$ and $3$ can be caught by the same robot, but apple $2$ must be caught by a different robot.

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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.