cswork / OAOpen practice workspace

AmazonOA #97

Assign Tasks to Servers

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsSimulation

Request i arrives at time i and lasts requests[i] seconds. Process requests in arrival order and choose the smallest currently free ID; when all servers are busy, wait for the earliest release time, and if several are released at the same time, choose the smallest ID. A 0-second request releases its server immediately. The source example does not follow the smallest-free-ID rule; this site corrects it according to the statement.

Input

The first line contains servers n, and the second line contains n durations. The original gives no numeric constraints; this site uses 1..100000 for both servers and n, and durations of 0..10⁹.

Output

Output the server ID assigned to each request, separated by spaces.

Example 1

Input:

5 5
3 1 0 2 1

Output:

0 1 1 0 1

Example 2

Input:

1 3
3 1 0

Output:

0 0 0

Example 3

Input:

2 3
2 1 1

Output:

0 1 0

Example notes

Example 1: at time 2, ID 1 has been released while 0 is not free until 3, so the five assignments are 0, 1, 1, 0, 1; the original source's 0, 1, 0, 2, 1 does not match the statement. Example 2: there is only ID 0, so all three requests go to it and the last two must queue. Example 3: at time 2 both servers are released at once, so the smaller ID 0 is chosen, giving 0, 1, 0.

Editorial

Loading solution…