← 返回 google 的题目列表Schedule Tasks on CPUs and Find the Minimum Number of CPUs
类型:online_judge
Problem: Schedule Tasks on CPUs and Find the Minimum Number of CPUs
Given n tasks. Each task has a fixed start time start and end time end, meaning it occupies one CPU during the half-open interval [start, end).
Each CPU can run at most one task at any time. If one task ends exactly when another task starts, they can use the same CPU.
Assign CPUs to all tasks and return the minimum number of CPUs required to execute all tasks without conflicts.
For judging, output:
First line: the minimum number of CPUs.
Second line: an array of length n, where the i-th number is the CPU id assigned to the i-th input task.
CPU ids start from 0. If multiple optimal assignments exist, output any one of them.
Input Format
The first line contains an integer n.
The next n lines each contain two integers start end.
Output Format
Print the minimum number of CPUs on the first line.
Print n integers on the second line representing the CPU assignment for each task.
Constraints
1 <= n <= 2 * 10^5
0 <= start < end <= 10^9
Example
Input:
3
0 30
5 10
15 20
Output:
2
0 1 1
Example
Input
3
0 30
5 10
15 20
Output
2
0 1 1