아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Ants on a Stick

메모리 제한1024 MB

요약
막대 위에서 걷다 부딪히면 방향을 바꾸는 개미들이 떨어지는 순서를 구한다. 충돌을 통과로 바꿔 계산한다.
난이도

보통10점 중 6점

유형
시뮬레이션, 정렬
정답자
아직 제출이 없습니다

문제

Ada has NN ants labelled from 11 to NN. She decides to test John's concentration skills. She takes a stick LL 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 PP, where ant ii is dropped at the position P_iP\_i (that is, P_iP\_i cm away from the left end) on the stick. Each ant travels either to the left or right with a constant speed of 11 cm per second. The initial directions of the ants is represented by an array DD, where the direction of ant ii is D_iD\_i: 00 if left, and 11 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, TT. TT test cases follow.

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

The next NN lines describe the positions and directions of the ants. The ii-th line contains two integers, P_iP\_i and D_iD\_i: the position and direction of ant ii, respectively.

출력

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

제한

  • 1≤T≤1001≤T≤100.
  • N\<LN\<L.
  • D_i∈0,1D\_i∈\\{0,1\\}, for all ii.
  • 0\<P_i\<L0\<P\_i\<L, for all ii.
  • All P_iP\_i are distinct.

예제1

  1. 예제 1

    입력
    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