CI Runner Dispatch
Your team's continuous-integration cluster has k identical runners, numbered 1 to k. At second 0
all of them are idle, and the build queue holds n jobs. Job i takes exactly d_i seconds to run,
on any runner.
The dispatcher handles the jobs strictly in queue order, job 1 first. For each job it picks the
runner that becomes free earliest; if several runners become free at that same second, it picks the
one with the smallest number. The job starts on that runner the moment the runner becomes free (so
at second 0 if the runner has never been used), and the runner is busy for the next d_i seconds.
A runner that finishes a job at second t can start its next job at second t.
For every job, report which runner it was dispatched to and the second at which it started.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2·10^5, 1 ≤ k ≤ 2·10^5): the number of
jobs and the number of runners.
The second line contains n integers d_1, d_2, …, d_n (1 ≤ d_i ≤ 10^9): the job durations in
seconds, in queue order.
Output
Print n lines. Line i must contain two integers: the number of the runner job i was dispatched
to, and the second at which job i started.
Notes
In the first example, jobs 1 and 2 start at second 0 on runners 1 and 2. Runner 2 frees up at second 1 and takes job 3, which ends at second 3. At that point both runners become free at second 3, so job 4 goes to runner 1 and job 5 to runner 2.
In the second example, all three runners free up at second 2, and the last three jobs fill them in order 1, 2, 3.
Start times can exceed the range of a 32-bit integer.