题目描述
Problem Description
Carpenter Cho-san has been entrusted with $N$ tasks. The $i$-th task starts at time $a_i$ and ends at time $b_i$.
Cho-san cannot handle multiple tasks at once, so he wants to select as many of these tasks as possible such that the times for working on the tasks do not overlap. However, he can start another task immediately after finishing one.
When there are multiple ways to select the maximum number of tasks, he wants to choose the tasks such that the sequence of their indices sorted by start time is lexicographically smallest.
Carpenter Cho-san is good at his work but seems to be not good at managing his schedule. Please find the optimal combination of tasks for him to undertake.
For two sequences of length $L$, $A=\{a_1,a_2,…,a_L\}$ and $B=\{b_1,b_2,…,b_L\}$, $A$ is lexicographically smaller than $B$ if there exists a $k(1≦k≦L)$ such that:
- $i < k$ where $a_i = b_i$
- $i = k$ where $a_i < b_i$
Input Format
The input is given from the standard input in the following format:
$N$ $a_1$ $b_1$ $a_2$ $b_2$ : $a_N$ $b_N$
- The first line contains an integer $N\ (1 ≦ N ≦ 100,000)$, representing the number of tasks entrusted to Cho-san.
- The next $N$ lines contain the information of the tasks entrusted to Cho-san. The $i$-th line contains two integers $a_i,\ b_i(0 ≦ a_i < b_i ≦ 1,000,000)$, representing the start and end times of the $i$-th task, separated by a space.
Output Format
The first line should contain the number of tasks Cho-san undertakes.
The second line should contain the indices of the tasks Cho-san undertakes, sorted by their start times, separated by a single space.
Do not forget the newline at the end of the output. Also, do not add extra spaces at the end.
Sample Input and Output
Sample Input #1
4
0 5
0 3
3 7
5 10
Sample Output #1
2
1 4
Sample Input #2
5
0 5
0 3
3 7
5 10
7 12
Sample Output #2
3
2 3 5
Sample Input #3
8
1 5
3 9
2 5
1 2
8 10
9 11
7 15
10 14
Sample Output #3
4
4 3 5 8
Notes/Hints
Sample Explanation 1
Cho-san can select a maximum of 2 tasks. There are 3 ways to select them, and he can choose tasks 1 and 4, or tasks 2 and 3, or tasks 2 and 4. Among these, the lexicographically smallest selection is tasks 1 and 4 because their indices sorted by start time are $\{1,4\}$, which is the lexicographically smallest sequence.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分