#P16767. [GKS 2020 #F] ATM Queue

[GKS 2020 #F] ATM Queue

Problem Description

There are NN people numbered from 11 to NN, standing in a queue to withdraw money from an ATM. The queue is formed in ascending order of their number. The person numbered ii wants to withdraw amount AiA_i. The maximum amount a person can withdraw at a time is XX. If they need more money than XX, they need to go stand at the end of the queue and wait for their turn in line. A person leaves the queue once they have withdrawn the required amount.

You need to find the order in which all the people leave the queue.

Input Format

The first line of the input gives the number of test cases TT. TT test cases follow.

The first line of each test case gives two space separated integers: the number of people standing in the queue, NN and the maximum amount XX that can be withdrawn in one turn.

The next line contains NN space separated integers AiA_i.

Output Format

For each test case, output one line containing Case #xx: yy`, where xx is the test case number (starting from 11) and yy is the space separated list of integers that denote the order in which the people leave the queue.

2
3 3
2 7 4
5 6
9 10 4 7 2
Case #1: 1 3 2
Case #2: 3 5 1 2 4

Hint

In Sample Case #11, there are 33 people and the limit to withdraw in one turn is 33. Below is step-by-step description of how the process will look like:

  • 11. The queue initially looks like [1,2,3][1, 2, 3]. The first person withdraws an amount of 22 in their first attempt and leaves the queue.
  • 22. The queue now looks like [2,3][2, 3]. The second person wants to withdraw an amount of 77, but they can withdraw only 33 in their first turn. Since they still need to withdraw an amount of 44, they have to rejoin the queue at the end of the line.
  • 33. The queue now looks like [3,2][3, 2]. The third person needs to withdraw an amount of 44 but they can only withdraw 33 in their first turn so, they rejoin the queue at the end of the line to withdraw amount of 11 later.
  • 44. The queue now looks like [2,3][2, 3]. The second person still needs to withdraw an amount of 44. They withdraw an amount of 33 in their second turn and waits for their next turn to arrive to withdraw the remaining amount of 11.
  • 55. The queue now looks like [3,2][3, 2]. The third person withdraws the remaining amount of 11 and leaves the queue.
  • 66. The queue now looks like [2][2]. The second person withdraws the remaining amount of 11 and leaves the queue.
  • 77. The queue is now empty.

The order in which people leave the queue is [1,3,2][1, 3, 2].

In Sample Case #22, there are 55 people and the limit to withdraw in one turn is 66. Below is step-by-step description of how the process will look like:

  • 11. The queue initially looks like [1,2,3,4,5][1, 2, 3, 4, 5]. The first person withdraws an amount of 66, and joins at the end again to withdraw the remaining amount of 33 later.
  • 22. The queue looks like [2,3,4,5,1][2, 3, 4, 5, 1]. The second person similarly withdraws an amount of 66 and waits for his next turn to withdraw an amount of 44.
  • 33. The queue looks like [3,4,5,1,2][3, 4, 5, 1, 2]. The third person withdraws an amount of 44 and leaves the queue.
  • 44. The queue now looks like [4,5,1,2][4, 5, 1, 2]. The fourth person withdraws 66 and waits for his next turn.
  • 55. The queue looks like [5,1,2,4][5, 1, 2, 4]. The fifth person withdraws amount of 22 and leaves the queue.
  • 66. The queue looks like, [1,2,4][1, 2, 4]. All other people now leave the queue after their second turn one by one.

The order in which people leave the queue is [3,5,1,2,4][3, 5, 1, 2, 4].

Limits

1T1001 \le T \le 100.

Test Set 11

1N1001 \le N \le 100.

1Ai1001 \le A_i \le 100.

1X1001 \le X \le 100.

Test Set 22

1N1051 \le N \le 10^5 for at most 1010 test cases. For the remaining cases, 1N1001 \le N \le 100.

1Ai1091 \le A_i \le 10^9.

1X1091 \le X \le 10^9.