시간 제한메모리 제한제출정답맞힌 사람정답 비율
서브태스크 참고 (추가 시간 없음) 1024 MB138675.000%

문제

Ada has $N$ ants labelled from $1$ to $N$. She decides to test John's concentration skills. She takes a stick $L$ cm long, and drops the ants on it.

The positions on the stick at which the ants are dropped are represented by an integer array $P$, where ant $i$ is dropped at the position $P_i$ (that is, $P_i$ cm away from the left end) on the stick. Each ant travels either to the left or right with a constant speed of $1$ cm per second. The initial directions of the ants is represented by an array $D$, where the direction of ant $i$ is $D_i$: $0$ if left, and $1$ if right. When two ants meet, they bounce off each other and reverse their directions. The ants fall off the stick when they reach either end of it.

Ada challenges John to find the exact order in which the ants fall off the stick. John needs your help!

입력

The first line of the input gives the number of test cases, $T$. $T$ test cases follow.

The first line of each test case contains two integers, $N$ and $L$: the number of ants, and the length of the stick, respectively.

The next $N$ lines describe the positions and directions of the ants. The $i$-th line contains two integers, $P_i$ and $D_i$: the position and direction of ant $i$, respectively.

출력

For each test case, output one line containing Case #x: A1A2…AN, where $x$ is the test case number (starting from 1), and $A_i$ is the label of the $i$-th ant that falls off the stick. In other words, the first ant to fall off the stick is the ant labelled $A_1$, the second is the ant labelled $A_2$, and so on. If multiple ants fall off at the same time, output their labels in the increasing order.

제한

  • $1≤T≤100$.
  • $N<L$.
  • $D_i∈\{0,1\}$, for all $i$.
  • $0<P_i<L$, for all $i$.
  • All $P_i$ are distinct.

Test Set 1 (11점)

시간 제한: 20 초

  • $1≤N≤10$.
  • $1≤L≤100$.

Test Set 2 (10점)

시간 제한: 40 초

  • $1≤N≤10^3$.
  • $1≤L≤10^9$.

Test Set 3 (12점)

시간 제한: 40 초

  • $1≤L≤10^9$.
  • For at most 15 cases:
    • $1≤N≤10^5$.
  • For the remaining cases:
    • $1≤N≤10^3$.

예제 입력 1

3
1 5
1 1
2 7
4 1
5 0
4 10
8 0
2 1
6 1
4 0

예제 출력 1

Case #1: 1
Case #2: 2 1
Case #3: 1 2 3 4

In Sample Case #1, as there is only a single ant (labelled $1$), it is the only one to fall off. The time at which it falls off is $4$ seconds.

In Sample Case #2, the two ants move towards each other, meet at $0.5$ seconds and reverse their directions. Ant $2$ then reaches the right end of the stick at $3$ seconds, whereas ant $1$ reaches the left end at $5$ seconds. Thus, ant $2$ falls off the stick, followed by ant $1$.

In Sample Case #3, ants $2$ and $4$ move towards each other and meet at $1$ second. Similarly, ants $1$ and $3$ also move towards each other and meet at $1$ second. All $4$ ants then change directions.

  • Ants $1$ and $2$ move towards either ends of the stick and fall off at $4$ seconds.
  • Ants $3$ and $4$ move towards each other and meet at $3$ seconds. They change directions and move towards either ends of the stick, and fall off at $8$ seconds.

채점 및 기타 정보

  • 예제는 채점하지 않는다.