[Solution] Ants on a Stick Solution Round C 2022 - Kick Start 2022
Problem
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
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
For each test case, output one line containing Case #:
, where is the test case number (starting from 1), 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.
Limits
Memory limit: 1 GB.
.
.
, for all .
, for all .
All are distinct.
Test Set 1
Time limit: 20 seconds.
.
.
Test Set 2
Time limit: 40 seconds.
.
.
Test Set 3
Time limit: 40 seconds.
.
For at most 15 cases:
.
For the remaining cases:
.
No comments:
Post a Comment