cswork / OA打开练习工作台

AmazonOA #97

Assign Tasks to Servers

估计中等可在线判题

考点(AI 标注)单调栈与堆模拟/实现

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.

输入格式

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 the server ID assigned to each request, separated by spaces.

样例 1

输入:

5 5
3 1 0 2 1

输出:

0 1 1 0 1

样例 2

输入:

1 3
3 1 0

输出:

0 0 0

样例 3

输入:

2 3
2 1 1

输出:

0 1 0

样例说明

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.