All problems

Printer Queue Rounds

Easy · queue

An office has one shared printer and a line of print jobs. Job i needs pages[i] pages, and the jobs are numbered by their starting place in the line (job 0 is at the front).

The printer works in turns. On each turn it takes the job at the front of the line and prints up to burst pages of it:

Return the job numbers in the order in which the jobs finish.

Examples

Example 1

Input: pages = [3, 1, 2], burst = 2

Output: [1, 2, 0]

Job 0 prints 2 pages and goes to the back. Job 1 prints its only page and finishes, then job 2 prints 2 pages and finishes. Job 0 returns for its last page.

Example 2

Input: pages = [2, 2, 2], burst = 5

Output: [0, 1, 2]

Every job fits into a single turn, so they finish in the order they started.

Example 3

Input: pages = [5, 5, 3], burst = 2

Output: [2, 0, 1]

Job 2 needs two turns while jobs 0 and 1 need three each.

Constraints