Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

In Queue

By Pranta07 · Limits 1s, 512 MB

There are NN students in a queue with ID 1,2,3,...,N1, 2, 3, ..., N respectively. Each student has some coins C1,C2,C3,....,CNC_1, C_2, C_3, ...., C_N. Minimum coins required for buying a meal from the canteen is MM.

  • Students are coming one after another. If CiMC_i \geq M, the ii'th student should buy a meal from the canteen. After buying the meal, he/she will leave the queue.
  • If Ci<MC_i < M then the student should go behind the queue and his/her coins will be increased by exactly 11.

The above process will repeat till the queue is not empty. Find the sequence of leaving the queue of NN students.


The first line contains an integer TT (1T103)\left(1 \leq T \leq 10^3\right), the number of test cases.

Then TT test cases follow -

The first line of each test case contains two integers NN (1N106)\left(1 \leq N \leq 10^6\right) and MM (1M109)\left(1 \leq M \leq 10^9\right). The second line of each test case contains NN integers C1,C2,C3,....,CNC_1, C_2 , C_3 , ...., C_N (1Ci109)\left( 1 \leq C_i \leq 10^9\right).

It is guaranteed that the sum of NN over all test cases does not exceed 10610^6.


For each test case, on a separate line print NN integers, the ID of NN students according to the sequence they left the queue.


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



75% Solution Ratio

ivanbrEarliest, 1M ago

coderUDFastest, 0.1s

user.455533Lightest, 15 MB

Humayra_037Shortest, 411B


Login to submit


This is a simple sorting problem. One thing you can notice here that there is no difference between ...