#P16879. [GKS 2022 #C] Ants on a Stick
[GKS 2022 #C] Ants on a Stick
Problem Description
Ada has ants labelled from to . She decides to test John's concentration skills. She takes a stick 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 , where ant is dropped at the position (that is, cm away from the left end) on the stick. Each ant travels either to the left or right with a constant speed of cm per second. The initial directions of the ants is represented by an array , where the direction of ant is : if left, and 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!
Input Format
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains two integers, and : the number of ants, and the length of the stick, respectively.
The next lines describe the positions and directions of the ants. The -th line contains two integers, and : the position and direction of ant , respectively.
Output Format
For each test case, output one line containing Case #: , where is the test case number (starting from ), and is the label of the -th ant that falls off the stick. In other words, the first ant to fall off the stick is the ant labelled , the second is the ant labelled , and so on. If multiple ants fall off at the same time, output their labels in the increasing order.
3
1 5
1 1
2 7
4 1
5 0
4 10
8 0
2 1
6 1
4 0
Case #1: 1
Case #2: 2 1
Case #3: 1 2 3 4
Hint
In Sample Case #, as there is only a single ant (labelled ), it is the only one to fall off. The time at which it falls off is seconds.
In Sample Case #, the two ants move towards each other, meet at seconds and reverse their directions. Ant then reaches the right end of the stick at seconds, whereas ant reaches the left end at seconds. Thus, ant falls off the stick, followed by ant .
In Sample Case #, ants and move towards each other and meet at second. Similarly, ants and also move towards each other and meet at second. All ants then change directions.
- Ants and move towards either ends of the stick and fall off at seconds.
- Ants and move towards each other and meet at seconds. They change directions and move towards either ends of the stick, and fall off at seconds.
Limits
.
.
, for all .
, for all .
All are distinct.
Test Set
.
.
Test Set
.
.
Test Set
.
For at most cases:
.
For the remaining cases:
.