AmazonOA #340
Schedule Requests to Servers
估计困难可在线判题
考点(AI 标注)缓存索引模拟/实现
There are servers servers, numbered 0..servers−1. Process n requests in order: request i can only be assigned to a server numbered from 0 to requests[i] (inclusive), and it goes to the least busy one among them; if several are equally least busy, choose the one with the smallest number. A server's busyness is the number of requests already assigned to it, and assigned requests are never released. Output the server number each request is assigned to.
输入格式
The first line contains two integers servers and n; the second line contains n integers requests[0..n−1]. 1≤servers≤100000, 1≤n≤200000, 0≤requests[i]<servers.
输出格式
Output one line of n integers separated by spaces; the i-th is the server number assigned to request i.
样例 1
输入:
5 5
3 1 0 2 1
输出:
0 1 0 2 1
样例 2
输入:
3 4
2 2 2 2
输出:
0 1 2 0
样例 3
输入:
4 4
0 0 3 3
输出:
0 0 1 2
样例说明
Example 1: servers=5, requests=[3,1,0,2,1]. For request 0, every server in 0..3 is idle, so choose 0; for request 1, server 1 is less busy within 0..1, so choose 1; request 2 can only choose 0; for request 3, server 2 has 0 assignments within 0..2, so choose 2; for request 4, within 0..1 server 0 has 2 and server 1 has 1, so choose 1. Output 0 1 0 2 1. Example 2: all three servers are available, and the requests go to 0, 1 and 2 in turn; at the fourth request each of the three has 1, so choose 0. Example 3: the first two requests can only use server 0; after that server 1 has the fewest assignments, so choose 1, then 2.